数据库SQL实战-答案解析(1-15)
地址:https://www.nowcoder.com/ta/sql
1、查找最晚入职员工的所有信息
select * from employees order by hire_date desc limit 1;
select * from employees order by hire_date desc limit 0,1;
LIMIT m,n : 表示从第m+1条开始,取n条数据;
LIMIT n : 表示从第0条开始,取n条数据,是limit(0,n)的缩写。
本题limit 0,1 表示从第(0+1)条数据开始,取一条数据,即取出最晚入职员工。
排序: order by 逆序 :desc
2、查找入职员工时间排名倒数第三的员工所有信息
select * from employees order by hire_date desc limit 2,1;
3、查找各个部门当前(to_date=’9999-01-01’)领导当前薪水详情以及其对应部门编号dept_no
select s.*, d.dept_no from salaries as s ,dept_manager as d where
s.to_date ='9999-01-01' and d.to_date ='9999-01-01' and s.emp_no = d.emp_no;
SELECT s.*, d.dept_no FROM salaries s , dept_manager d
WHERE s.to_date='9999-01-01'
AND d.to_date='9999-01-01'
AND s.emp_no = d.emp_no;
select s.*,d.dept_no from salaries s
left join dept_manager d
on s.emp_no=d.emp_no
where d.to_date='9999-01-01'AND