Skip to main content
SQL โ€ข LESSON 157

Cumulative Department Salary

How can we explicitly specify a window frame from the start of the department partition?

Advancedโฑ 3 Minutesโญ 1700 XP
๐Ÿค” THE QUESTION

How can we explicitly specify a window frame from the start of the department partition?

๐Ÿ’ก WHAT IS IT?

ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW explicitly defines an unbounded cumulative window frame.

๐ŸŽฏ WHAT IS IT USED FOR?

Strict cumulative aggregation, deterministic financial totals in streaming pipelines.

๐Ÿ’ป EXAMPLE
SELECT
department_id,
name,
salary,
SUM(salary) OVER (
    PARTITION BY department_id
    ORDER BY salary
    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS cumulative_salary
FROM employees;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for Cumulative Department Salary.

  • โœ“ Window frame specification
  • โœ“ UNBOUNDED PRECEDING
  • โœ“ CURRENT ROW
  • โœ“ Explicit cumulative frame