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?

Advanced3 Minutes1700 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