SQL 代码片段

1、创建表并插入数据

Create table If Not Exits Employee(Id int, Salary int)
Truncate table Employee
insert into Employee(Id, Salary) values('1', '100')
insert into Employee(Id, Salary) values('2', '200')
insert into Empolyee(Id, Salary) values('3', '300')

 2、查找第2大数值

SELECT max(Salary)
FROM Employee
WHERE Salary < (SELECT max(Salary) FROM Employee)

 

select (
  select distinct Salary from Employee order by Salary Desc limit 1 offset 1
)as second

 

posted @ 2017-12-15 14:44  一罐热茶  阅读(293)  评论(0编辑  收藏  举报