力扣
题目要求当没有第二高的薪水时,输出null。
首先力扣不支持nvl函数,使用ifnull替换。
但是ifnull必须要套住整个查询,否则输出还是为空。如下第一段代码是不能通过用例测试的。
select IFNULL(salary,"null") as SecondHighestSalary
from (# Write your MySQL query statement below
select salary , dense_rank() over(order by salary desc) as rk
from Employee) as a
where rk=2
其输出为:
能通过用例测试的代码为:
select IFNULL(
(select distinct salary
from (# Write your MySQL query statement below
select salary , dense_rank() over(order by salary desc) as rk
from Employee) as a
where rk=2)
,null) as SecondHighestSalary