Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Organizational Hierarchy Traversal | Recursive CTEs and Hierarchical Data
Mastering Common Table Expressions (CTEs) in SQL
Секція 2. Розділ 2
single

single

bookChallenge: Organizational Hierarchy Traversal

Свайпніть щоб показати меню

Завдання

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_id matches any employee already found.
  • Include a column for reporting level, incremented at each recursion.
  • Return employee_id, name, position, and reporting_level for all subordinates found.
  • Order the results by reporting_level and employee_id.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 2. Розділ 2
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt