PrepZone Logo
PrepZone
Back to Database

Database · Hard

Print the full reporting hierarchy under a manager with the depth level.

DatabaseSQL QueriesStaffRecursive CTE

Answer preview

Walk the manager_id chain with a WITH RECURSIVE CTE: an anchor row for the top of the tree, plus a recursive term that joins each employee to the level above and increments a depth counter.…