You have two tables: Employee and Department.
The Employee table contains employee information including their salary and department ID. The Department table contains department names.
A company's executives want to see who earns the most money in each department. A high earner in a department is an employee who has a salary in the top three unique salaries for that department.
Task: Find all employees who are high earners in their respective departments.
Note: The result should include the department name, employee name, and salary. Return results in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
id
PK
|
int | Primary key, unique employee identifier |
name
|
varchar | Employee name |
salary
|
int | Employee salary |
departmentId
|
int | Foreign key referencing Department.id |
| Column Name | Type | Description |
|---|---|---|
id
PK
|
int | Primary key, unique department identifier |
name
|
varchar | Department name |
Input & Output
| id | name | salary | departmentId |
|---|---|---|---|
| 1 | Joe | 85000 | 1 |
| 2 | Henry | 80000 | 2 |
| 3 | Sam | 60000 | 2 |
| 4 | Max | 90000 | 1 |
| 5 | Janet | 69000 | 1 |
| 6 | Randy | 85000 | 1 |
| 7 | Will | 70000 | 1 |
| id | name |
|---|---|
| 1 | IT |
| 2 | Sales |
| Department | Employee | Salary |
|---|---|---|
| IT | Max | 90000 |
| IT | Joe | 85000 |
| IT | Randy | 85000 |
| IT | Will | 70000 |
| Sales | Henry | 80000 |
| Sales | Sam | 60000 |
In the IT department: Max has the highest salary (90000, rank 1), Joe and Randy tie for second highest (85000, rank 2), and Will has the third highest (70000, rank 3). In Sales department: Henry has the highest (80000, rank 1) and Sam has second highest (60000, rank 2). All are within top 3 unique salaries for their departments.
| id | name | salary | departmentId |
|---|---|---|---|
| 1 | Alice | 95000 | 1 |
| 2 | Bob | 75000 | 1 |
| id | name |
|---|---|
| 1 | Engineering |
| Department | Employee | Salary |
|---|---|---|
| Engineering | Alice | 95000 |
| Engineering | Bob | 75000 |
Engineering department has only 2 employees, both qualify as top 3 earners. Alice ranks 1st with 95000, Bob ranks 2nd with 75000. Since there are fewer than 3 unique salary levels, all employees are included.
Constraints
-
1 ≤ Employee.id ≤ 100 -
1 ≤ Department.id ≤ 100 -
1 ≤ salary ≤ 1000000 - Employee names and department names are non-empty strings
- Each employee belongs to exactly one department