RANK: Rank Employees by Salary (With Gaps)
SQL coding challenge · Difficulty: easy · +50 XP
Problem
HR is building a salary leaderboard where tied employees share the same rank — but the next rank skips a number *(like Olympic medals: 1st, 1st, 3rd)*.
Tables
Table: employees_wf
| emp_id | emp_name | department | salary | | 101 | John | IT | 90000 | | 102 | Alice | IT | 75000 | | 103 | Bob | IT | 75000 | | 104 | David | HR | 80000 | | 105 | Emma | HR | 65000 |
Expected Output
| emp_id | emp_name | salary | rank_num | | 101 | John | 90000 | 1 | | 104 | David | 80000 | 2 | | 102 | Alice | 75000 | 3 | | 103 | Bob | 75000 | 3 | | 105 | Emma | 65000 | 5 |
- Return:
emp_id,emp_name,salary,rank_num - Tied employees share the same rank, next rank skips
- Sort by
salarydescending - Function to use:
RANK()