Top Three Salaries
Beginner Mode
Objective
Write a SQL query to find the top 3 highest-paid employees within each department.
Table Schema:
employee
| Column | Type | Description |
|---|---|---|
| employee_id | INTEGER | Unique identifier for each employee |
| employee_name | VARCHAR | Name of the employee |
| salary | DECIMAL | Employee's salary |
| department_id | INTEGER | ID of the department where the employee works |
| hire_date | DATE | Date when the employee was hired |
department
| Column | Type | Description |
|---|---|---|
| department_id | INTEGER | Unique identifier for each department |
| department_name | VARCHAR | Name of the department |
Task Requirements:
- Join employee and department tables
- Identify the top 3 highest-paid employees in each department
- Order by department name (ascending), then salary (descending), then employee name (ascending)
Output columns: employee_name, department_name, salary
Examples
Example 1:
Output:
Input:
| department | |
|---|---|
| department_id | department_name |
| 1 | Engineering |
| 2 | Marketing |
| employee | ||||
|---|---|---|---|---|
| department_id | employee_id | employee_name | hire_date | salary |
| 1 | 1 | Alice Johnson | 2020-01-15 | 95000 |
| 1 | 2 | Bob Smith | 2021-03-20 | 85000 |
| 1 | 3 | Carol Davis | 2019-06-10 | 90000 |
| 2 | 4 | David Wilson | 2022-02-05 | 78000 |
| 2 | 5 | Emma Brown | 2021-08-12 | 82000 |
| department_name | employee_name | salary |
|---|---|---|
| Engineering | Alice Johnson | 95000 |
| Engineering | Carol Davis | 90000 |
| Engineering | Bob Smith | 85000 |
| Marketing | Emma Brown | 82000 |
| Marketing | David Wilson | 78000 |
Code Environment
Sign in or try as guest to run your code.
Track
| Question | Difficulty | Company | Access |
|---|
Need more practice in this area? Explore more questions →
Microsoft