SQL Cumulative Sum
The exact same idea as a running total — this is just the name analytics and BI tools tend to use for it.
What & Why
"Cumulative sum" and "running total" describe the identical calculation. If you've seen one, you already understand the other — this lesson exists purely so both names are covered.
See How It Works
BUSINESS QUESTION
Growth wants cumulative signups over time.
| date_day | dau | new_users | returning_users |
|---|---|---|---|
| 2024-04-01 | 1240 | 180 | 1060 |
| 2024-04-02 | 1315 | 205 | 1110 |
| 2024-04-03 | 1288 | 164 | 1124 |
| 2024-04-04 | 1392 | 221 | 1171 |
EXAMPLE QUERY
SELECT
date_day,
new_users,
SUM(new_users) OVER (ORDER BY date_day ROWS UNBOUNDED PRECEDING) AS cumulative_signups
FROM growth.daily_active_users
ORDER BY date_day;RESULT — cumulative signups
| date_day | new_users | cumulative_signups |
|---|---|---|
| 2024-04-01 | 180 | 180 |
| 2024-04-02 | 205 | 385 |
| 2024-04-03 | 164 | 549 |
| 2024-04-04 | 221 | 770 |
Each row includes all earlier new-user values.
This lesson's practice is part of Pro.
Sign up free to try it on a real business scenario