176.第二高的薪水
链接:176.第二高的薪水
难度:Medium
标签:数据库
简介:查询并返回 Employee 表中第二高的 不同 薪水 。如果不存在第二高的薪水,查询应该返回 null(Pandas 则返回 None) 。
题解 1 - sql
- 编辑时间:2024-10-15
- 执行用时:3662ms
- 编程语言:sql
- 解法介绍:遍历
select if(count(*) = 0, null, salary) as SecondHighestSalary
from Employee e1
where (
select count(distinct e2.salary)
from Employee e2
where e2.salary > e1.salary
) = 1