热线电话:13121318867

登录
2020-06-02 阅读量: 918
SQL:查找入职员工时间排名倒数第三的员工所有信息:LZ (半世清欢)

S
题目描述查找入职员工时间排名倒数第三的员工所有信息:
CREATE TABLE `employees` (
`emp_no` int(11) NOT NULL,
`birth_date` date NOT NULL,
`first_name` varchar(14) NOT NULL,
`last_name` varchar(16) NOT NULL,
`gender` char(1) NOT NULL,
`hire_date` date NOT NULL,
PRIMARY KEY (`emp_no`));

解题思路:
1、先对入职时间hire_date倒数第三进行判断:
(1)考虑入职时间可能相同,所以要先对hire_date进行去重排序
(2)去重排序后用limit选择倒数第三:limit [偏移量,] 行数
select distinct hire_date
from employees
order by hire_date desc
limit 2,1;
2、把第一步得到的倒数第三的时间作为子集语句插入语句
select *
from employees
where hire_date in (
select distinct hire_date
from employees
order by hire_date desc
limit 2,1
);

13.9240
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子