Best Paid in Each Department
Return the dept, name and salary of the best paid person of every department. When several people share the top salary of a department, return all of them. Rows may come in any order.
Example 1
employees
| id | name | dept | salary |
|---|---|---|---|
| 1 | Ada | ops | 5000 |
| 2 | Ben | ops | 5000 |
| 3 | Cy | ops | 4000 |
| 4 | Dee | risk | 6000 |
| 5 | Eli | risk | 3000 |
returns
| dept | name | salary |
|---|---|---|
| ops | Ada | 5000 |
| ops | Ben | 5000 |
| risk | Dee | 6000 |
Constraints
- Up to 12 people
- Names are unique
Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.
More SQL problems
- Bought but Never SoldMedium
- Change From the Day BeforeMedium
- First OrderMedium
- Latest PriceMedium
- More Than the ManagerMedium
- Open PositionsMedium
- Rank in the DepartmentMedium
- Revenue per CityMedium