Use SUM() OVER for cumulative metrics.
Section: CTEs and window functions
Compute a running total
sql
sql
SELECT created_at,
amount,
SUM(amount) OVER (ORDER BY created_at) AS running_total
FROM invoices;Explanation
Great for revenue charts and time-series analytics.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing CTEs and window functions