Write a SQL query to get the second highest salary from the Employee table.
For example, given the above Employee table, the query should return 200 as the second highest salary. If these is no second highest salary, then the query should return null.
Unofficial Answer:
SELECT MIN(v.Salary) FROM Employee AS v INNER JOIN (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 2) AS v2 ON v.Salary = v2.Salary
SELECT MIN(v2.Salary) AS v FROM (SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT 2) AS v2
© 著作权归作者所有
举报
发表评论
0/200