【LeetCode】176.第二高的薪水

176.第二高的薪水

编写一个 SQL 查询语句,获取Employee表中第二高的薪水(Salary)。

【LeetCode】176.第二高的薪水_第1张图片

用到的表和数据SQL:

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)  SecondHighestSalary
from Employee where (select Max(Salary)from Employee) > Salary

写的比较粗糙,有不理解的可以扫描二维码加QQ群找我解答。

【LeetCode】176.第二高的薪水_第2张图片


你可能感兴趣的:(LeetCode(数据库),LeetCode(数据库部分))