Running total of order value
Your task
Given orders with columns order_id, customer, amount, status and placed, return a running total of amount in placed order as running, taking orders placed on the same day in order_id order. Return order_id and running, sorted by placed ascending and then order_id ascending.
Examples
running_total(orders: dataframe) -> dataframeExample 1
Input
running_total(orders)orders
| order_id | customer | amount | status | placed |
|---|---|---|---|---|
| 1 | ada | 120.5 | paid | 2024-01-05 |
| 2 | bo | 80 | refunded | 2024-01-07 |
| 3 | ada | 45.25 | paid | 2024-02-11 |
| 4 | cy | 200 | paid | 2024-02-14 |
| 5 | bo | 15.75 | pending | 2024-03-02 |
| 6 | ada | 60 | paid | 2024-03-19 |
Output
| order_id | running |
|---|---|
| 1 | 120.5 |
| 2 | 200.5 |
| 3 | 245.75 |
| 4 | 445.75 |
| 5 | 461.5 |
| 6 | 521.5 |