获取员工其当前的薪水比其manager当前薪水还高的相关信息,当前表示to_date='9999-01-01',
获取员工其当前的薪水比其manager当前薪水还高的相关信息
http://www.nowcoder.com/questionTerminal/f858d74a030e48da8e0f69e21be63bef
可以简化问题先建立两张临时表 步骤一:建立表a查询出员工号(emp_no)、emp_no对应的manager_no、员工薪水emp_salary (select de.emp_no,dm.emp_no as manager_no,s.salary as emp_salary from dept_emp de join dept_manager dm on de.dept_no=dm.dept_no join salaries s on de.emp_no=s.emp_no where de.to_date='9999-01-01' and s.to_date='9999-01-01') as a 其中de.to_date='9999-01-01' and s.to_date='9999-01-01'目的是筛选出当前员工的当前工资 步骤二:建立表b查询出经理的员工号manager_no、经理薪水manager_salary (select dm.emp_no as manager_no,s.salary as manager_salary from dept_manager dm join salaries s on dm.emp_no=s.emp_no where dm.to_date='9999-01-01' and s.to_date='9999-01-01') as b 步骤三:利用manager_no为关键字联合查询a、b,并增加查询条件 a.emp_salary>b.manager_salary查找比自己经理工资高的员工 select a.emp_no,a.manager_no,a.emp_salary,b.manager_salary from (select de.emp_no,dm.emp_no as manager_no,s.salary as emp_salary from dept_emp de join dept_manager dm on de.dept_no=dm.dept_no join salaries s on de.emp_no=s.emp_no where de.to_date='9999-01-01' and s.to_date='9999-01-01') as a join (select dm.emp_no as manager_no,s.salary as manager_salary from dept_manager dm join salaries s on dm.emp_no=s.emp_no where dm.to_date='9999-01-01' and s.to_date='9999-01-01') as b on a.manager_no=b.manager_no where a.emp_salary>b.manager_salary;