Rank in the Department
Return every person's name, dept and salary, and rnk: their place in their own department by salary, 1 for the best paid. People on the same salary share a place, and the places after them are skipped: 1, 1, 3. 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
| name | dept | salary | rnk |
|---|---|---|---|
| Ada | ops | 5000 | 1 |
| Ben | ops | 5000 | 1 |
| Cy | ops | 4000 | 3 |
| Dee | risk | 6000 | 1 |
| Eli | risk | 3000 | 2 |
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
- Revenue per CityMedium
- Running BalanceMedium
- Second From the TopMedium
- Share of the TotalMedium
- Volume Weighted PriceMedium
- Chain of CommandHard
- Daily BarsHard
- Longest Winning StreakHard