#791

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.

idnamesubtree_salary
1CEO1315000
2VP-Eng610000
3VP-Sales305000

Your query result will appear here