第二高工资

2019-07-29  本文已影响0人  Sam_6155
image.png

解法一:剔除最大值再考虑再提取最大值法
Select max(Salary) AS SecondHighestSalary from Employee
where Salary not in(
Select max(Salary) from Employee)
解法二:ifnull()函数
select
ifnull((select
distinct(salary) SecondHighestSalary
from employee
order by salary desc
limit 1,1),null) SecondHighestSalary
解法三:不知道为什么一直报错?目前无解,待以后再搞明白
SELECT CASE WHEN Salary is not null THEN Salary ELSE null
END SecondHighestSalary
FROM Employee
ORDER BY Salary DESC
LIMIT 1,1;

上一篇 下一篇

猜你喜欢

热点阅读