176. Second Highest Salary#1

来源:互联网 发布:自学日语教材知乎 编辑:程序博客网 时间:2024/05/17 07:11

Solutin#1

# Write your MySQL query statement belowSELECT MAX(Salary) AS SecondHighestSalaryFROM EmployeeWHERE Salary < (SELECT MAX(Salary) FROM Employee)#Using max() will return a NULL #if the value doesn't exist. #So there is no need to UNION a NULL. #Of course, if the second highest value is guaranteed to exist, using LIMIT 1,1 will be the best answer.

Solution#2

SELECT (SELECT DISTINCT SalaryFROM Employee ORDER BY Salary DESC LIMIT 1 OFFSET 1) AS SecondHighestSalary #利用了Limit 1,同时在外圈加一圈选择满足了Null的情况
0 0
原创粉丝点击