leetcode 第二高薪水

problem

直接查询如果不存在第二高的Salary不会返回值,所以应该用子查询

select (select distinct Salary from Employee order by Salary desc limit 1,1) as SecondHighestSalary

也可以用IFNULL
ifnull(exr1,exr2) 如果exr1是null那么返回exr2否则返回exr1

select ifnull( (select distinct Salary from Employee order by Salary desc limit 1 offset 1), NULL) as SecondHighestSalary
select max(Salary) as SecondHighestSalary from Employee where Salary <> (select max(Salary) from Employee)