FunctionRacerProblemsRace

Chain of Command

HardSQLSQLite

manager_id is the id of a person's manager, a row of the same table, and NULL for a person at the top. Return every person's name and depth: the number of managers above them, following the chain to the top. Someone at the top has depth 0, their direct reports 1, and so on. Rows may come in any order.

Example 1

employees
idnamemanager_id
1AdaNULL
2Ben1
3Cy2
4Dee1
5EliNULL
returns
namedepth
Ada0
Ben1
Cy2
Dee1
Eli0

Constraints

Race itor take your time

Write it in your browser, against the clock. The model query, with a note on each piece of it, comes after.

More SQL problems