SELECT HOUR(t.transaction_date) hour,COUNT(t.id) transactions,SUM(t.final_total) revenue,LAG(SUM(t.final_total)) OVER (ORDER BY HOUR(t.transaction_date)) prev_hour_revenue,COUNT(DISTINCT t.contact_id) unique_customers FROM transactions t WHERE t.type="sell" GROUP BY HOUR(t.transaction_date) ORDER BY revenue DESC;