Skip to main content
SQL • LESSON 153

Salary Rank by Department

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

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