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_daydaunew_usersreturning_users
2024-04-0112401801060
2024-04-0213152051110
2024-04-0312881641124
2024-04-0413922211171
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_daynew_userscumulative_signups
2024-04-01180180
2024-04-02205385
2024-04-03164549
2024-04-04221770

Each row includes all earlier new-user values.

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario