先找出经理的部门,员工号,工资, 然后找出员工的部门,员工号,工资,最后用部门连接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;