The Answer of FB's SQL Question
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
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: