Most recent order for each customer
Your task
Given orders with columns order_id, customer, amount, status and placed, return the latest order per customer, breaking ties on placed by the larger order_id. Return customer, order_id and amount, sorted by customer ascending.
Examples
latest_order(orders: dataframe) -> dataframeExample 1
Input
latest_order(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 | order_id | amount |
|---|---|---|
| ada | 6 | 60 |
| bo | 5 | 15.75 |
| cy | 4 | 200 |