All tasks

Employee Path to CEO (Hierarchy)

Advanced

Classic recursive CTE task. **Condition:** For each employee, build the full path in the organizational hierarchy from them to the CEO. **Table:** org_employees (employee_id, name, manager_id, department, salary, level) **Requirements:** 1. Use recursive CTE 2. Path in format: "CEO -> Director -> Manager -> Employee" 3. Output employee_id, name, path, depth (level from CEO) **Hint:** Anchor member — CEO (manager_id IS NULL), recursive member — JOIN by manager_id.

Category
Recursive CTE
Estimated time
~25 min
Databases
PostgreSQLGreenplum
Tags
InterviewRecursive CTEHierarchyTreeрекурсия

Sign in to solve

Start Solving