Skip to main content
SQL โ€ข LESSON 153

Salary Rank by Department

How can we rank employees within their department handling ties with gaps?

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

How can we rank employees within their department handling ties with gaps?

๐Ÿ’ก WHAT IS IT?

RANK() with PARTITION BY provides competition-style ranking within localized groups.

๐ŸŽฏ WHAT IS IT USED FOR?

Department leaderboards, sales performance tiers, quota rankings.

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

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for Salary Rank by Department.

  • โœ“ Partitioned RANK
  • โœ“ Department leaderboard
  • โœ“ Tie handling
  • โœ“ Rank resets