-- Created on savesnippets.com ยท https://savesnippets.com/8uWXcoRwZHEcLz -- Cumulative revenue by day SELECT day, revenue, SUM(revenue) OVER (ORDER BY day) AS running_total FROM daily_revenue; -- Running total per user SELECT user_id, created_at, amount, SUM(amount) OVER ( PARTITION BY user_id ORDER BY created_at ) AS lifetime_value FROM orders; -- Cumulative % of total SELECT day, revenue, SUM(revenue) OVER (ORDER BY day) AS cumulative, SUM(revenue) OVER () AS grand_total, ROUND(100.0 * SUM(revenue) OVER (ORDER BY day) / SUM(revenue) OVER (), 1) AS cumulative_pct FROM daily_revenue ORDER BY day;