Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Architectural Logic**: Window function with unbounded preceding for running total. **Implementation**: `SELECT date, amount, SUM(amount) OVER (ORDER BY date) AS cumulative_sum FROM sales`. Per group: `SUM(amount) OVER (PARTITION BY product_id ORDER BY date)`. **Frame**:...
Architectural Logic: Window function with unbounded preceding for running total. Implementation: SELECT date, amount, SUM(amount) OVER (ORDER BY date) AS cumulative_sum FROM sales. Per group: SUM(amount) OVER (PARTITION BY product_id ORDER BY date). Frame: Default ROWS UNBOUNDED PRECEDING. Use: Running balance; YTD. Scalability: Single pass; efficient. Cost: No extra scan. Best Practice: Deterministic ORDER BY (tie-breaker if needed); understand RANGE vs ROWS. In Spark: same syntax.
Red Flag: Application-side loop for running total—inefficient. Pro-Move: Window SUM with ORDER BY; ROWS vs RANGE for ties; PARTITION BY for per-group; cite in-database efficiency.
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.