Part 98: Cumulative Running Totals & Moving Averages
Running balances are ubiquitous in banking, inventory, and SaaS subscription tracking.
1. Running Total Syntax
SELECT
transaction_date,
amount,
SUM(amount) OVER (
ORDER BY transaction_date, id
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS account_balance
FROM bank_transactions;
Key Takeaways
SUM() OVER (ORDER BY ...)calculates cumulative balances on the fly.
In Part 99, we explore Named Windows with the WINDOW Clause!

