题解 | #获取员工其当前的薪水比其manager当前薪水还高的相关信息#
获取员工其当前的薪水比其manager当前薪水还高的相关信息
http://www.nowcoder.com/practice/f858d74a030e48da8e0f69e21be63bef
先两表联查 输出 emp_no, dept_no 和对应的 manager_no
select t1.*,t2.emp_no manager_no
from dept_emp t1 left join dept_manager t2 using(dept_no)
然后在刚才输出表的基础上 连接 salaries 输出加上 emp_salary 以 emp_no = manager_no 连接 输出 manager_salary
select t.*,t3.salary emp_salary,t4.salary manager_salary from
(select t1.*,t2.emp_no manager_no
from dept_emp t1 left join dept_manager t2 using(dept_no)) t
join salaries t3 using(emp_no)
join salaries t4 on t.manager_no=t4.emp_no
最后在上表基础上 判断emp_salary>manager_salary 按条件输出
select emp_no,manager_no,emp_salary,manager_salary from
(select t.*,t3.salary emp_salary,t4.salary manager_salary from
(select t1.*,t2.emp_no manager_no
from dept_emp t1 left join dept_manager t2 using(dept_no)) t
join salaries t3 using(emp_no)
join salaries t4 on t.manager_no=t4.emp_no) tt
where emp_salary>manager_salary