Chapter 9 · Interview Level
18. Cumulative Spending Per Customer
Medium20 XPE-Commerce
For each customer's orders, calculate a running total of their spending over time. Return customer_id, order_date, total_amount, and cumulative_spending (the sum of all their orders up to and including the current one). If a customer has two orders on the same date, add them in order id order. Sort by customer_id, then order_date.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- order_dateTEXT
- statusTEXT
- total_amountREAL
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.