Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Rank Employees Within Department

For each employee return name, department_id, salary and salary_rank, where the rank is based on salary descending within the department. Equal salaries share a rank and no rank numbers are skipped (dense ranking). Order by department_id, salary_rank, name.

Table schema

Employees(id INT PRIMARY KEY, name VARCHAR(50), department_id INT, salary INT)

Sample data

id | name | department_id | salary
1 | Alice | 1 | 9000
2 | Bob | 1 | 8000
3 | Carol | 1 | 9000
4 | Dan | 2 | 7000
5 | Eve | 2 | 6000

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.