Skip to content

Instantly share code, notes, and snippets.

@niisar
Created May 19, 2014 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niisar/9d65fc7e07bbb99863ff to your computer and use it in GitHub Desktop.
Save niisar/9d65fc7e07bbb99863ff to your computer and use it in GitHub Desktop.
determine if an employee is earning the same salary as his/her manager.
WITH RSFC(EMPID,ENAME,MGRID,LVL,SAL) AS
(SELECT EMPLOYEE_ID,
EMPLOYEE_NAME,
MANAGER_ID,
0 AS LVL,
SALARY
FROM COMPANY
WHERE MANAGER_ID IS NULL
UNION ALL
SELECT EMPLOYEE_ID,
EMPLOYEE_NAME,
MANAGER_ID,
LVL+1,
SALARY
FROM RSFC R
INNER JOIN COMPANY F
ON F.MANAGER_ID = R.EMPID
) cycle SAL
SET IS_CYCLE TO 'Y' DEFAULT 'N'
SELECT * FROM RSFC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment