Explain how you would handle complex SQL queries, including cases that involve recursion.
Write a PostgreSQL query that expands the reachable reporting hierarchy from employees whose manager is NULL. Exclude employees whose manager cannot be reached from a root, and protect the query from revisiting an employee in the same path.
employee_id, employee_name, root_employee_id, depth, and hierarchy_pathdepth is 0 for each rootroot_employee_id| Column | Type | Description |
|---|---|---|
| employee_idPK | INT | Unique employee identifier |
| employee_name | VARCHAR(100) | Employee display name |
| manager_id | INT | Employee ID of the direct manager |