SQL · Pattern 10 — Window Functions
Running Total
Calculates cumulative totals.
Source data — Pattern 10: Window Functions
All queries run against the shared employees table (see schema.sql). This pattern introduces a sales table to demonstrate window functions including ranking, navigation, running totals, moving averages and window aggregates.


What it does
Calculates cumulative totals.
Problem
Calculate cumulative sales.
SELECT *,
SUM(sales_amount) OVER(ORDER BY sale_month) AS result
FROM sales;
Result
