Count of orders by customer and status
Your task
Given orders with columns order_id, customer, amount, status and placed, count the orders for each customer and status pair. Return customer, status and n, sorted by customer ascending and then status ascending. Pairs that never occur do not appear.
Examples
status_counts(orders: dataframe) -> dataframeExample 1
Input
status_counts(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
| customer | status | n |
|---|---|---|
| ada | paid | 3 |
| bo | pending | 1 |
| bo | refunded | 1 |
| cy | paid | 1 |