查询一张表中第二高的数,难点在于如何解决不存在第二高的数的情况
使用临时表
select
(select distinct Salary from Employee order by Salary desc limit 1,1)
as SecondHighestSalary
使用ifnull函数
select
ifnull((select distinct Salary from Employee order by Salary desc limit 1,1),null)
as SecondHighestSalary