本题有两种解法
方法一:inner join
思路:本题的重点在于获取非manager员工,因此我们使用inner join
将employees,dept_emp,salaries
表进行连接,在 where 条件中加入
e.emp_no not in (select emp_no from dept_manager where to_date = '9999-01-01')
来进行判断,由此来排除掉是manager的员工。
select de.dept_no, e.emp_no, s.salary
from employees e, dept_emp de, salaries s
where e.emp_no = de.emp_no and e.emp_no = s.emp_no and e.emp_no not in (select emp_no from dept_manager where to_date = '9999-01-01')
方法二:利用left join
与 is null
进行判空取差集
select de.dept_no, de.emp_no, s.salary
from salaries as s
join dept_emp as de on de.emp_no = s.emp_no
left join dept_manager as dm on dm.emp_no = de.emp_no
where dm.emp_no is null
and s.to_date='9999-01-01'