题解 | #获取员工其当前的薪水比其manager当前薪水还高的相关信息#
获取员工其当前的薪水比其manager当前薪水还高的相关信息
http://www.nowcoder.com/practice/f858d74a030e48da8e0f69e21be63bef
select d.emp_no, t.emp_no, s.salary, t.salary from dept_emp as d join salaries as s on d.emp_no = s.emp_no join ( select dept_no, dd.emp_no, salary from dept_manager as dd join salaries as s on dd.emp_no = s.emp_no ) as t on d.dept_no = t.dept_no where d.emp_no != t.emp_no and s.salary > t.salary
新建表t为每个部门领导的员工编号和工资对照表
将t与员工表按部门编号为连接条件连接,然后在把领导剔除,同时增加工资大于的条件