Your question is Running Total With Window Functions. Start with the requirements and the one table on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Sparksoft wants to show each user's cumulative spend over time in its analytics view. Write a SQL query to calculate a running total of order amounts for every user, ordered by purchase date.
user_id, order_date, order_amount, and the cumulative spend as running_total.user_id, then order_date, then order_id.| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique identifier for each order |
| user_id | INT | Identifier of the user who placed the order |
| order_date | DATE | Date when the order was created |
| order_amount | DECIMAL(10,2) | Order value, may be NULL for incomplete records |
| channel | VARCHAR(20) | Order source channel |