RANK vs DENSE_RANK: See the Difference Side by Side
SQL coding challenge · Difficulty: easy · +50 XP
Problem
A new analyst wants to understand the difference between RANK and DENSE_RANK. Show both side by side in a single query.
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 | dense_rank_num | | 101 | John | 90000 | 1 | 1 | | 104 | David | 80000 | 2 | 2 | | 102 | Alice | 75000 | 3 | 3 | | 103 | Bob | 75000 | 3 | 3 | | 105 | Emma | 65000 | 5 | 4 |
- Return:
emp_id,emp_name,salary,rank_num,dense_rank_num - Sort by
salarydescending