题解 | #获取员工其当前的薪水比其manager当前薪水还高的相关信息#
获取员工其当前的薪水比其manager当前薪水还高的相关信息
http://www.nowcoder.com/practice/f858d74a030e48da8e0f69e21be63bef
先找出经理的部门,员工号,工资, 然后找出员工的部门,员工号,工资,最后用部门连接2表, 取得答案
with a as
(select m.dept_no, m.emp_no as manager_no, s.salary as manager_salary
from salaries s
join dept_manager m
on s.emp_no = m.emp_no
where s.to_date='9999-01-01'),
b as
(select e.dept_no, e.emp_no, s.salary as emp_salary
from dept_emp e
join salaries s
on e.emp_no = s.emp_no
where e.to_date='9999-01-01')
select b.emp_no, a.manager_no, b.emp_salary, a.manager_salary
from a
join b
on a.dept_no = b.dept_no
where emp_salary > manager_salary;
(select m.dept_no, m.emp_no as manager_no, s.salary as manager_salary
from salaries s
join dept_manager m
on s.emp_no = m.emp_no
where s.to_date='9999-01-01'),
b as
(select e.dept_no, e.emp_no, s.salary as emp_salary
from dept_emp e
join salaries s
on e.emp_no = s.emp_no
where e.to_date='9999-01-01')
select b.emp_no, a.manager_no, b.emp_salary, a.manager_salary
from a
join b
on a.dept_no = b.dept_no
where emp_salary > manager_salary;