leetcode 176

发布时间 2023-03-29 16:53:57作者: Carl_ZhangJH

leetcode 176 第二高的薪水,查第二高的人的信息

1、使用ifnull(exp1, exp2)函数,limit offset子句

 

select ifnull( 
(select distinct salary 
from Employee 
order by salary 
desc limit 1 offset 1),
 null) 
as SecondHighestSalary

 

limit 1 offset 1 等同于 limit 1,1
第一个1代表从第几条开始取,最开始的index是第0条。
 
2、使用 子查询 以及 limit offset子句
select (
select distinct salary  
from Employee 
order by salary desc 
limit 1 offset 1
) as SecondHighestSalary