自用

查找入职员工时间排名倒数第三的员工所有信息

http://www.nowcoder.com/questionTerminal/ec1ca44c62c14ceb990c3c40def1ec6c

select * from employees
where hire_date =
(select distinct hire_date from employees order by hire_date desc limit 1 offset 2);

关键在这一句

select distinct hire_date from employeesorder by hire_date desc limit 1 offset 2

distinct 去重

SQL查询语句中的 limit 与 offset 的区别:

limit y 分句表示: 读取 y 条数据

limit x, y 分句表示: 跳过 x 条数据,读取 y 条数据

limit y offset x 分句表示: 跳过 x 条数据,读取 y 条数据

比如分页获取数据:

第1页: 从第0个开始,获取20条数据

select * from testtable limit 0, 20; 
等价于
select * from testtable limit 20 offset 0;  

第2页: 从第20个开始,获取20条数据

select * from testtable limit 20, 20; 
等价于
select * from testtable limit 20 offset 20;  

第3页: 从第40个开始,获取20条数据

select * from testtable limit 40, 20;  
等价于
select * from testtable limit 20 offset 40;   
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务