题解 | #查找入职员工时间排名倒数第三的员工所有信息#
查找入职员工时间排名倒数第三的员工所有信息
http://www.nowcoder.com/practice/ec1ca44c62c14ceb990c3c40def1ec6c
两种解法:
1、使用子查询方式
SELECT * FROM employees
WHERE hire_date = (
SELECT hire_date FROM employees
ORDER BY hire_date DESC
LIMIT 2,1);
limit用法:
LIMIT m,n : 表示从第m+1条开始,取n条数据;
LIMIT n : 表示从第0条开始,取n条数据,是limit(0,n)的缩写。
2、使用窗口函数方式:
select emp_no,birth_date,first_name,last_name,gender,hire_date
from(
select *,
dense_rank() over(order by hire_date desc )as n
from employees
) a
where n=3;