LeetCode--176.第二高的薪水

在这里插入图片描述

建表

Create table If Not Exists Employee (Idint, Salary int);
Truncate table Employee;
insert into Employee (Id, Salary) values('1', '100');
insert into Employee (Id, Salary) values('2', '200');
insert into Employee (Id, Salary) values('3', '300');
  • 第一种思路

比最高薪水小的最高的薪水即是第二高薪水

select Max(Salary) 
from Employee111 where (select Max(Salary) from Employee111) != Salary
  • 第二种思路

分页查询

select Salary from Employee111 ORDER BY Salary desc limit 1, 1
  • 第三种思路

开窗函数,取top2

select * from (
 select Id, Salary, row_number() over(ORDER BY Salary desc) ranks from Employee111 
) t where t.ranks=2

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42363032/article/details/108862997