runtime
45 / 88

task Recursive CTEs · hard

Management chain for every employee

Starting from every employee with no manager, return id, name, level (top = 1) and chain: the names from the top of the hierarchy down to the employee, joined by ' > '.

what to return

Columns
idnamelevelchain in this order
Rows
20 rows · any order
Watch for
There can be more than one person with no manager — each starts their own tree.
A top-level chain is just that person's name.
Skill
Traverse a tree with a recursive CTE. Refresher: Self-joins & referral relationships →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result20 rows · any order
idnamelevelchain
1Ada Moreno1Ada Moreno
19Sana Iqbal1Sana Iqbal
2Bruno Costa2Ada Moreno > Bruno Costa

first 3 of 20 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

employees7 columns · 20 rows
idinteger · keynametextmanager_idinteger → employeesdepartment_idinteger → departmentstitletextsalaryrealhired_attext
1Ada MorenoNULLNULLCEO2500002019-03-01
2Bruno Costa11VP Engineering1800002019-06-15
3Carmen Diaz12VP Sales1500002020-01-10
4Dev Patel21Engineering Manager1400002020-05-04
5Elif Kaya41Senior Engineer1450002021-02-01

showing 5 of 20 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.