解题的思路就是,假如知道 员工的薪水 还有对应manager的薪水,然后进行比较,高的写1 低或者等于写2,筛选出1 即可,所以就是多表链接凑员工薪水和manager 薪水
select
emp_no,
manager_no,
salary,
manager_salary
from
(select
c.emp_no,
c.salary,
c.manager as manager_no,
d.salary as manager_salary,
if(c.salary>d.salary,1,2) as level1
from
(select
a.emp_no,
a.salary,
b.manager
from
salaries a
left join
(SELECT
a.emp_no,
b.dept_no,
b.emp_no as manager
FROM
dept_emp a
LEFT JOIN dept_manager b ON a.dept_no = b.dept_no)b
on a.emp_no=b.emp_no)c
left join
salaries d
on c.manager=d.emp_no) e
where level1=1