leetcode 176. Second Highest Salary

xiaoxiao2021-02-28  98

176. Second Highest Salary 1. 建表

create table if not exists Employee ( Id int(10) not null auto_increment, Salary int(20) default null, primary key(Id) )ENGINE=InnoDB DEFAULT CHARSET=utf8; insert into Employee(Salary) values(100); insert into Employee(Salary) values(200); insert into Employee(Salary) values(300); select * from Employee;

2.答案

select ( select distinct Salary from Employee order by Salary Desc limit 1 offset 1 )as SecondHighestSalary select max(Salary) as SecondHighestSalary from Employee where Salary <> (select max(Salary) from Employee); select max(Salary) as SecondHighestSalary from Employee where Salary !=(select max(Salary) from Employee) SELECT max(Salary) as SecondHighestSalary FROM Employee WHERE Salary < (SELECT max(Salary) FROM Employee); SELECT max(Salary) as SecondHighestSalary From Employee WHERE Salary not in (SELECT max(Salary) FROM Employee )
转载请注明原文地址: https://www.6miu.com/read-17653.html

最新回复(0)