Skip to main content
SQL • LESSON 151

Partitioned Running Total

How can we calculate cumulative payroll separately for each department?

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