题解 | #获取所有员工当前的manager#
获取所有员工当前的manager
http://www.nowcoder.com/practice/e50d92b8673a440ebdf3a517b5b37d62
答案:
SELECT d.emp_no,dd.emp_no as manager FROM dept_emp d LEFT JOIN dept_manager dd ON d.dept_no=dd.dept_no WHERE d.emp_no NOT IN (SELECT de.emp_no FROM dept_emp de INNER JOIN dept_manager dep ON (de.dept_no=dep.dept_no AND de.emp_no=dep.emp_no) )
1.首先找出是经理的员工编号
SELECT de.emp_no FROM dept_emp de INNER JOIN dept_manager dep ON (de.dept_no=dep.dept_no AND de.emp_no=dep.emp_no)
2.然后not in剩下的就是员工的编号
``SELECT d.emp_no,dd.emp_no as manager FROM dept_emp d LEFT JOIN dept_manager dd ON d.dept_no=dd.dept_no WHERE d.emp_no NOT IN`
```