解决方案一:
不考虑不存在第二高薪水的情况
先按分数排序–逆序,然后通过limit取第二个
limit 1,1 表示从下标为1开始取,取一个值
select distinct salary as SecondHighestSalary from Employee
order by salary desc limit 1,1
考虑不存在第二高薪水的情况
IFNULL() 函数用于判断第一个表达式是否为 NULL,如果为 NULL 则返回第二个参数的值,如果不为 NULL 则返回第一个参数的值。
select ifnull(
(select distinct Salary from Employee order by Salary desc limit 1,1),null
) as SecondHighestSalary