418. Reporting Chain Depth

Hard Startup Organizational Analytics
Query Rules
  • The query columns and order must match the expected result schema.
  • NULL values should be handled appropriately where applicable.
  • The grader compares output values and sorting order to evaluate.

Schema Browser

Click a table's header to toggle expand/collapse.
locations
3 cols
departments
3 cols
employees
6 cols
orders
6 cols

Reference Solution

Expected SQL
WITH RECURSIVE hierarchy AS (SELECT emp_id, manager_id, 0 AS level FROM employees WHERE manager_id IS NULL UNION ALL SELECT e.emp_id, e.manager_id, h.level + 1 FROM employees e JOIN hierarchy h ON e.manager_id = h.emp_id) SELECT level, COUNT(*) AS employee_count FROM hierarchy GROUP BY level ORDER BY level;
SQL Editor
Ctrl+Enter to run
Console Output

Console Terminal

Write your query and click "Run Query" (Ctrl + Enter) to see results and testcase validation.