思路:
- 先用INNER JOIN连接salaries和demp_emp,建立当前所有员工的工资记录sem;
- 再用INNER JOIN连接salaries和demp_manager,建立当前所有员工的工资记录sdm;
- 最后用限制条件sem.dept_no = sdm.dept_no AND sem.salary >
sdm.salary找出同一部门中工资比经理高的员工,并根据题意依次输出emp_no、manager_no、emp_salary、manager_salary;
SELECT
de.dept_no,
e.emp_no,
s.salary
FROM
employees AS e
INNER JOIN dept_emp AS de ON e.emp_no = de.emp_no
INNER JOIN salaries AS s ON e.emp_no = s.emp_no
WHERE
de.to_date = '9999-01-01'
AND s.to_date = '9999-01-01'
AND e.emp_no NOT IN (
SELECT
emp_no
FROM
dept_manager
WHERE
to_date = '9999-01-01'
)