Premium problem27. Second Distinct Salary

Medium Locked

employees(employee_id, department_id, salary)

Return second_highest_salary: the second-highest distinct salary across the whole company, or NULL when fewer than two distinct salaries exist.

Several people on the top salary does not make that salary the second-highest. The NULL case is part of the answer, so returning no rows is wrong.

Tables

employees

employee_id  department_id  salary
-----------  -------------  ---------
1            1              150000.00
2            1              150000.00
3            2              120000.00
4            2              90000.00

Expected result

second_highest_salary
---------------------
120000.00

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query