Show how each product's stock evolved over time
Same warehouse arrival/shipment event log, but now we need not the final stock but the stock at each point in time — the cumulative sum of deltas from the start up to the current row in time order, separately per product. Show the product id, the timestamp, and the running stock at that moment. Sort by product id, then by time.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.
| ts | delta | balance | product_id |
|---|---|---|---|
| 2024-01-01T00:00:00.000Z | 10 | 10 | 1 |
| 2024-01-05T00:00:00.000Z | -2 | 8 | 1 |
| 2024-01-10T00:00:00.000Z | -1 | 7 | 1 |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign in