Skip to main content
SQL โ€ข LESSON 152

Partitioned Average

How can we project departmental average compensation across each record?

Advancedโฑ 3 Minutesโญ 1650 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