Each manager's reporting line cost
For every employee in the company compute the cost of their reporting line — the total salary of their direct and indirect reports at any depth (the employee themselves is not included). Employees with no reports get an empty value. Show the employee id, name, and the sum, sort by id. Subtle point: if someone has reports but they all earn zero, the sum should be zero, not empty — distinguish «no reports at all» from «reports exist and their salary sum equals zero».
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.
| id | name | subtree_salary |
|---|---|---|
| 1 | CEO | 1315000 |
| 2 | VP-Eng | 610000 |
| 3 | VP-Sales | 305000 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in