Section 2. Chapitre 2
single
Challenge: Organizational Hierarchy Traversal
Glissez pour afficher le menu
Tâche
Swipe to start coding
Write a recursive CTE to list all employees who report, directly or indirectly, to a specified manager in the employees table. For each subordinate, include their employee_id, name, position, and their reporting level (1 for direct report, 2 for their direct reports, etc.). The result should be ordered by reporting level and employee ID.
- Use a recursive CTE to traverse the hierarchy starting from employees who report directly to the given manager.
- For each recursive step, find employees whose
manager_idmatches any employee already found. - Include a column for reporting level, incremented at each recursion.
- Return
employee_id,name,position, andreporting_levelfor all subordinates found. - Order the results by
reporting_levelandemployee_id.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 2. Chapitre 2
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion