题目:获取员工其当前薪水比其manager当前薪水还高的相关信息,当前表示to_date=‘9999-01-01’,
结果第一列给出员工的emp_no,
第二列给出其manager的manager_no,
第三列给出该员工当前的薪水emp_salary,
第四列给出该员工对应的manager当前的薪水manager_salary
方法1:构建员工工资表和管理工资表,然后两表联查
SELECT a.emp_no, b.manager_no, a.emp_salary, b.manager_salary
FROM
(SELECT de.dept_no, de.emp_no, s.salary AS emp_salary
FROM dept_emp AS de, salaries AS s
WHERE de.emp_no=s.emp_no
AND de.to_date='9999-01-01'
AND s.to_date='9999-01-01') AS a,
(SELECT dm.dept_no, dm.emp_no AS manager_no, s.salary AS manager_salary
FROM dept_manager AS dm, salaries AS s
WHERE dm.emp_no=s.emp_no
AND dm.to_date='9999-01-01'
AND s.to_date='9999-01-01') AS b
WHERE a.dept_no=b.dept_no
AND a.emp_salary>b.manager_salary;