SQL: Employee Hierarchy
Medium
SQL — Advanced
SQL
CTE
Recursion
Build employee hierarchy path.
Constraints
Write standard SQL (MySQL 8.0 compatible).
Examples
Example 1:
Input: id name mgr
1 CEO null
2 VP 1
3 Dir 2
Output:
Example 2:
Input: id name mgr
1 CEO null
2 VP 1
3 Dir 2
Output:
Hints
Recursive CTE.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console