Return the second highest salary in each department. If a department has fewer than two distinct salaries, return null for that department. Ties on salary count once.
employees, ordered by department_idemployees| salary | employee_id | department_id |
|---|---|---|
| 90000 | 1 | 10 |
| 70000 | 2 | 10 |
| 50000 | 3 | 20 |
| 40000 | 4 | 20 |
| department_id | second_salary |
|---|---|
| 10 | 70000 |
| 20 | 40000 |
employees| salary | employee_id | department_id |
|---|---|---|
| 90000 | 1 | 10 |
| 90000 | 2 | 10 |
| 70000 | 3 | 10 |
| department_id | second_salary |
|---|---|
| 10 | 70000 |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.