Skip to main content
SQL โ€ข LESSON 151

Partitioned Running Total

How can we calculate cumulative payroll separately for each department?

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

How can we calculate cumulative payroll separately for each department?

๐Ÿ’ก WHAT IS IT?

Combining PARTITION BY with ORDER BY computes running totals that reset at each department boundary.

๐ŸŽฏ WHAT IS IT USED FOR?

Department-level cumulative spending, regional quota tracking, isolated running metrics.

๐Ÿ’ป EXAMPLE
SELECT
department_id,
name,
salary,
SUM(salary) OVER (
    PARTITION BY department_id
    ORDER BY salary
) AS department_running_total
FROM employees;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for Partitioned Running Total.

  • โœ“ Partitioned cumulative sum
  • โœ“ Running total reset
  • โœ“ Department payroll tracking
  • โœ“ Window boundaries