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.
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.