题解 | #获取员工其当前的薪水比其manager当前薪水还高的相关信息#
获取员工其当前的薪水比其manager当前薪水还高的相关信息
http://www.nowcoder.com/practice/f858d74a030e48da8e0f69e21be63bef
SELECT staff.emp_no,manager.emp_no AS manager_no,staff.all_salary AS emp_salary,manager.ma_salary AS manager_salary
FROM (SELECT A.emp_no,A.dept_no,B.salary AS all_salary
FROM dept_emp A JOIN salaries B
ON A.emp_no = B.emp_no) AS staff
LEFT JOIN (SELECT C.emp_no,C.dept_no,D.salary AS ma_salary
FROM dept_manager C INNER JOIN salaries D
ON C.emp_no = D.emp_no) AS manager
ON staff.dept_no = manager.dept_no
WHERE staff.all_salary >manager.ma_salary