Using a CTE, first compute each customer's total spending (sum of their invoice totals). Then, from that CTE, return only the customers whose total spending exceeds $40.
Return CustomerId, FirstName, LastName, and TotalSpent, ordered by TotalSpent descending (ties broken by CustomerId ascending).
| Column | Type |
|---|---|
| CustomerId | INTEGER (Primary Key) |
| FirstName | TEXT |
| LastName | TEXT |
| Column | Type |
|---|---|
| InvoiceId | INTEGER (Primary Key) |
| CustomerId | INTEGER (Foreign Key -> Customer.CustomerId) |
| InvoiceDate | TIMESTAMP |
| Total | NUMERIC(10,2) |
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.