Employee hierarchy with queries: build a structure over an employee hierarchy and answer queries, similar to tries / Design In-Memory File System.
Asked in the onsite stage. Write a SQL query that reports hierarchy statistics for every active employee.
employee_id, employee_name, direct_reports, total_reports, and max_reporting_depth.total_reports descending, then employee_id ascending.| Column | Type | Description |
|---|---|---|
| employee_idPK | INT | Unique employee identifier |
| employee_name | VARCHAR(100) | Employee's full name |
| job_title | VARCHAR(100) | Employee's job title |
| employment_status | VARCHAR(20) | Employment status, such as active or inactive |
| Column | Type | Description |
|---|---|---|
| ancestor_id | INT | An employee with one or more descendants |
| descendant_id | INT | A direct or indirect report |
| depth | INT | Number of reporting levels between ancestor and descendant |