AlgoMaster Logo

Window Aggregates: Running Totals and Moving Averages

Last Updated: May 3, 2026

9 min read

SUM, AVG, and COUNT collapse rows into a single result when used with GROUP BY. But sometimes you need a cumulative sum that grows row by row, or a rolling average over the last few entries, while keeping every row visible.

That's what window aggregates do: they run an aggregate function across a sliding or expanding frame of rows, producing one result per row instead of one result per group.

Premium Content

Subscribe to unlock full access to this content and more premium articles.