Window Function Running Total
Compute running totals with SQL window functions for cumulative aggregation over ordered rows.
Code
SELECT
date,
revenue,
SUM(revenue) OVER (ORDER BY date) AS running_total,
SUM(revenue) OVER (ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS weekly_sum
FROM daily_revenue
ORDER BY date;Report a problem with this exampleOpens a pre-filled issue on GitHub.