显示薪水低于其经理但超过使用ORACLE SQL查询的任何其他经理的薪水的员工

时间:2016-03-09 13:42:05

标签: sql database oracle11g oracle10g informatica-powercenter

显示薪水低于其经理但超过使用ORACLE SQL查询的任何其他经理的薪水的员工

1 个答案:

答案 0 :(得分:0)

WITH mgr_salaries ( empno, ename, esal, mgr, mgr_salary ) AS (
  SELECT empno,
         ename,
         salary,
         mgr,
         PRIOR salary
  FROM   Employees
  START WITH mgr IS NULL
  CONNECT BY PRIOR empno = mgr
)
SELECT *
FROM   mgr_salaries
WHERE  salary < mgr_salary
AND    NOT EXISTS (
         SELECT 1
         FROM   mgr_salaries x
         WHERE  x.mgr <> m.mgr
         AND    x.mgr_salary > m.salary
       );