Skip to main content
SQL • LESSON 28

SQL Running Totals

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

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