Advertisement
Guest User

Untitled

a guest
May 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. -- Write only the SQL statement that solves the problem and nothing else.
  2. With EmployeeCTE (id, managerId, name)
  3. AS
  4. (
  5. SELECT id, managerId, name
  6. FROM employees
  7. WHERE managerId is NULL
  8.  
  9. UNION ALL
  10.  
  11. SELECT employees.id, employees.managerId, employees.name
  12. FROM employees
  13. JOIN EmployeeCTE
  14. on employees.managerId = EmployeeCTE.id
  15. )
  16.  
  17. SELECT EmpCTE.name AS Employee
  18. FROM EmployeeCTE EmpCTE
  19. JOIN EmployeeCTE MgrCTE
  20. ON EmpCTE.managerId = MgrCTE.id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement