Skip to main content
SQL โ€ข LESSON 147

Running Total

How can we compute cumulative revenue over time?

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

How can we compute cumulative revenue over time?

๐Ÿ’ก WHAT IS IT?

SUM() OVER (ORDER BY date) accumulates values incrementally from the start of the partition.

๐ŸŽฏ WHAT IS IT USED FOR?

Cumulative sales charts, year-to-date spend curves, burn rate tracking.

๐Ÿ’ป 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 Running Total.

  • โœ“ Cumulative SUM
  • โœ“ Running total
  • โœ“ Time-series accumulation
  • โœ“ Financial trajectory