Skip to main content
SQL โ€ข LESSON 28

SQL Running Totals

How do we calculate cumulative sums or running totals across time?

Advancedโฑ 3 Minutesโญ 500 XP
๐Ÿค” THE QUESTION

How do we calculate cumulative sums or running totals across time?

๐Ÿ’ก WHAT IS IT?

SUM() OVER (ORDER BY ...) creates an expanding cumulative aggregation window across ordered rows.

๐ŸŽฏ WHAT IS IT USED FOR?

Cumulative revenue, balance tracking, burn-down charts, rolling metrics in financial dashboards.

๐Ÿ’ป EXAMPLE
SELECT order_date,
amount,
SUM(amount) OVER (
  ORDER BY order_date
) AS running_total
FROM orders;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for SQL Running Totals.

  • โœ“ Cumulative SUM()
  • โœ“ Running total
  • โœ“ OVER (ORDER BY)
  • โœ“ Time-series analytics