Skip to main content
SQL • LESSON 152

Partitioned Average

How can we project departmental average compensation across each record?

Advanced3 Minutes1650 XP
🤔 THE QUESTION

How can we project departmental average compensation across each record?

💡 WHAT IS IT?

AVG() OVER (PARTITION BY ...) calculates group benchmarks while preserving all underlying records.

🎯 WHAT IS IT USED FOR?

Departmental pay benchmarking, outlier detection, variance modeling.

💻 EXAMPLE
SELECT
department_id,
name,
salary,
AVG(salary) OVER (
    PARTITION BY department_id
) AS department_average
FROM employees;

🎯 Mission Objectives

Practice typing production-grade SQL code for Partitioned Average.

  • Partitioned average
  • Group benchmark
  • Row preservation
  • Compensation analysis