7. Employee Hierarchy Levels
MediumRecursive CTEsWITH RECURSIVEhierarchylevel counter
employees is an org chart: each row points at its manager via
manager_id. The CEO has manager_id = NULL.
Task: return every employee's name and their level in the hierarchy,
where the CEO is level 1, their direct reports are level 2, and so on.
Order by level, then name.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.