leetcode 176. Second Highest Salary

来源:互联网 发布:电子挂历制作软件 编辑:程序博客网 时间:2024/06/05 15:05

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 SecondHighestSalaryselect 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 EmployeeWHERE Salary < (SELECT max(Salary) FROM Employee);SELECT max(Salary) as SecondHighestSalaryFrom EmployeeWHERE Salary not in (SELECT max(Salary) FROM Employee )
原创粉丝点击