数据库SQL实践2:查找入职员工时间排名倒数第三的员工所有信息

思想:

题目要求查找入职员工时间排名倒数第三的员工所有信息。首先通过一个子查询(select distinct hire_date from employees order by hire_date desc limit 2,1)查找出入职员工时间排名倒数第三的入职时间hire_date,然后通过where hire_date = (select distinct hire_date from employees order by hire_date desc limit 2,1) 找到入职员工时间排名倒数第三的员工的记录,最后通过select * from employees取出所有信息。

知识点:

1.distinct 去除重复hire_date

2.order by 对hire_date进行排序。默认是按升序排序,desc 按逆序排序

3.limit 2,1 取出第条记录。limit m,n 指从m+1开始取n条记录

SELECT * FROM employees
where hire_date = 
(select distinct hire_date from employees ORDER BY hire_date DESC LIMIT 2,1);

猜你喜欢

转载自blog.csdn.net/weixin_43160613/article/details/83472916
今日推荐