Loading problem...
You are given two relational tables:
For each department, identify salary bands using unique salary values sorted from high to low. An employee is classified as a high earner if their salary belongs to one of the top three unique salary bands inside that employee's department.
Important details:
Return exactly these columns:
The result can be returned in any order.
This problem should be solvable in both:
Employee:
| id | name | salary | departmentId |
|----|-------|--------|--------------|
| 1 | Mina | 96000 | 10 |
| 2 | Theo | 91000 | 10 |
| 3 | Aria | 91000 | 10 |
| 4 | Zane | 87000 | 10 |
| 5 | Lila | 82000 | 10 |
| 6 | Omar | 73000 | 20 |
| 7 | Noor | 61000 | 20 |
Department:
| id | name |
|----|-----------|
| 10 | Platform |
| 20 | Support |[
{"Department":"Platform","Employee":"Mina","Salary":96000},
{"Department":"Platform","Employee":"Theo","Salary":91000},
{"Department":"Platform","Employee":"Aria","Salary":91000},
{"Department":"Platform","Employee":"Zane","Salary":87000},
{"Department":"Support","Employee":"Omar","Salary":73000},
{"Department":"Support","Employee":"Noor","Salary":61000}
]Explanation
Platform has unique salaries 96000, 91000, 87000, 82000. Only the first three salary levels qualify, so Lila is excluded. Support has only two unique salaries, so both employees qualify.
Employee:
| id | name | salary | departmentId |
|----|-------|--------|--------------|
| 8 | Ravi | 120000 | 30 |
| 9 | Inez | 120000 | 30 |
| 10 | Kira | 120000 | 30 |
Department:
| id | name |
|----|-----------|
| 30 | Security |[
{"Department":"Security","Employee":"Ravi","Salary":120000},
{"Department":"Security","Employee":"Inez","Salary":120000},
{"Department":"Security","Employee":"Kira","Salary":120000}
]Explanation
There is a single unique salary band, so everyone in that department is part of the top three distinct salary bands.
Employee:
| id | name | salary | departmentId |
|----|--------|--------|--------------|
| 11 | Elena | 150000 | 40 |
| 12 | Bruno | 140000 | 40 |
| 13 | Gita | 130000 | 40 |
| 14 | Pavel | 120000 | 40 |
Department:
| id | name |
|----|--------------|
| 40 | Data Science |[
{"Department":"Data Science","Employee":"Elena","Salary":150000},
{"Department":"Data Science","Employee":"Bruno","Salary":140000},
{"Department":"Data Science","Employee":"Gita","Salary":130000}
]Explanation
Only employees within the top three distinct salary bands are returned. Pavel is in the fourth distinct salary band and is excluded.
Constraints