自用

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

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;   
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务