Skip to main content
SQL • LESSON 147

Running Total

How can we compute cumulative revenue over time?

Advanced3 Minutes1600 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