首页 > 开发 > 综合 > 正文

176. Second Highest Salary#1

2024-07-21 02:51:16
字体:
来源:转载
供稿:网友

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的情况
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表