第一种解法:找到员工薪水、经理薪水 连接两表 比较
select
a.emp_no, b.emp_no, a.salary, b.salary
from(
-- 员工薪水
select de.dept_no, sa.emp_no, sa.salary from salaries sa join dept_emp de on sa.emp_no = de.emp_no)a
JOIN
-- 经理薪水
(select dm.dept_no, s1.emp_no, s1.salary from salaries s1 join dept_manager dm on s1.emp_no = dm.emp_no)b
on a.dept_no = b.dept_no and a.emp_no <> b.emp_no
where a.salary > b.salary
第二种解法:员工表、经理表、关系表、工资表、工资表联合查询,然后筛选条件
select de.emp_no,dm.emp_no as manager_no,
s1.salary as emp_salary,s2.salary as manager_salary
FROM
dept_emp de,dept_manager dm, salaries s1, salaries s2
where de.dept_no = dm.dept_no
and de.emp_no = s1.emp_no
and dm.emp_no = s2.emp_no
and s1.salary > s2.salary