How can we rank employees within their department handling ties with gaps?
RANK() with PARTITION BY provides competition-style ranking within localized groups.
Department leaderboards, sales performance tiers, quota rankings.
SELECT
department_id,
name,
salary,
RANK() OVER (
PARTITION BY department_id
ORDER BY salary DESC
) AS salary_rank
FROM employees;Practice typing production-grade SQL code for Salary Rank by Department.