Reviewed by Aditya Kumar · Last reviewed 2026-03-24
SELECT region, year, month, SUM(sales) OVER (PARTITION BY region, year ORDER BY month ROWS UNBOUNDED PRECEDING) AS running_total FROM sales ORDER BY region, year, month. **Why**: Cumulative sum = SUM with ORDER BY and default frame. ROWS UNBOUNDED PRECEDING explicit....
SELECT region, year, month, SUM(sales) OVER (PARTITION BY region, year ORDER BY month ROWS UNBOUNDED PRECEDING) AS running_total FROM sales ORDER BY region, year, month. Why: Cumulative sum = SUM with ORDER BY and default frame. ROWS UNBOUNDED PRECEDING explicit. Scalability: Ensure (region, year, month) supports partition pruning.
Red Flag: RANGE vs ROWS—RANGE can be slower with ties. Pro-Move: 'ROWS for performance; we pre-aggregate to month for dashboards.'
According to DataEngPrep.tech, this is one of the most frequently asked SQL interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.