Who's Third in Line, Pay-Wise?
Kestrel Labs is publishing an internal pay-scale reference and the top of it is being built by hand, one rung at a time. The first two rungs are already written down. The analyst has come back for the third: the person standing third from the top of the company pay list.
There is no column that says so. "Third" is not a fact about anybody's row — it only becomes true once all ten people are lined up against one another, which is what makes counting into a list a different move from filtering rows.
Pin the definition before you start. "Third" here means positional: line everybody up best paid first and take the person standing third. Had two people shared the top salary, that reading would hand back somebody still on the second-highest figure, whereas "the third different salary in the company" would skip past both of them. This report wants the positional one.
employees — one row per person. salary is annual pay in dollars.
| id | name | department_id | salary | hire_date | manager_id |
|---|---|---|---|---|---|
| 1 | Ava Chen | 1 | 145000 | 2021-03-14 | NULL |
| 2 | Ben Ortiz | 1 | 118000 | 2022-06-01 | 1 |
| 3 | Cara Novak | 1 | 121000 | 2023-01-10 | 1 |
| 4 | Deshawn Lee | 2 | 95000 | 2020-09-23 | NULL |
| 5 | Elin Kask | 2 | 88000 | 2022-11-05 | 4 |
| 6 | Farid Amiri | 3 | 76000 | 2023-04-18 | NULL |
| 7 | Grace Kim | 4 | 132000 | 2021-07-30 | NULL |
| 8 | Hugo Silva | 4 | 110000 | 2023-02-14 | 7 |
| 9 | Ines Duarte | 4 | 104000 | 2023-08-01 | 7 |
| 10 | Jonas Weber | 2 | 91000 | 2021-12-19 | 4 |
The table already exists in the database — there is nothing to create or load.
Task: Write a query returning exactly one row with two columns, name and salary, for the employee standing third from the top when everybody is arranged with the best paid first. Ties, if there were any, occupy separate positions rather than sharing one.
Example output — shape only, on an invented payroll.
| name | salary |
|---|---|
| Mira Kovac | 128500 |
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in