How SQL Window Frames Control Running Totals, Explained with Real Data
Data analyst Michael Nocito published a practical SQL guide on August 8, 2026, explaining how window frame clauses determine the outcome of running total calculations. The tutorial demonstrates that omitting the ROWS BETWEEN clause causes SQL to use a default frame, which can produce incorrect cumulative figures when column values are repeated. Using a dataset of 16 orders totalling 9,890 in revenue loaded into DuckDB, Nocito walks through the exact syntax — SUM(revenue) OVER (ORDER BY month ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) — to build accurate cumulative columns. The guide also covers partitioned running totals, moving averages, and a verification method to confirm results against the table's grand total. The SQL dialect used is close to PostgreSQL, making the examples directly transferable to Postgres, Redshift, and Snowflake.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in