For each manager, compute the total sales their entire organizational subtree generated (the manager's direct reports, their reports, and so on).
| Column | Type |
|---|---|
| EmployeeId | INTEGER (PK) |
| LastName | TEXT NOT NULL |
| FirstName | TEXT NOT NULL |
| Title | TEXT |
| ReportsTo | INTEGER (FK → Employee) |
| BirthDate | TIMESTAMP |
| HireDate | TIMESTAMP |
| Country | TEXT |
| Column | Type |
|---|---|
| CustomerId | INTEGER (PK) |
| FirstName | TEXT NOT NULL |
| LastName | TEXT NOT NULL |
| Company | TEXT |
| Country | TEXT |
| TEXT NOT NULL | |
| SupportRepId | INTEGER (FK → Employee) |
| Column | Type |
|---|---|
| InvoiceId | INTEGER (PK) |
| CustomerId | INTEGER (FK) |
| InvoiceDate | TIMESTAMP NOT NULL |
| BillingCountry | TEXT |
| Total | NUMERIC(10,2) NOT NULL |
WITH RECURSIVE CTE to build the manager → subordinate transitive closureCustomer.SupportRepIdManagerName, ManagerTitle, SubtreeSales (rounded to 2 decimals)Ready to take your skills to the next level? Enroll in our comprehensive Data Analyst Career Track to master SQL, Python, Excel, and Power BI.
Run your code to see the result here.