#831

Compute current stock from a log of arrivals and sales

The warehouse system doesn't keep current stock as a dedicated column — it writes every arrival and every shipment as a separate row in inventory_events.delta: a positive number is incoming, negative is outgoing. Current stock per product is just the sum of all its deltas. For every product compute the current stock as an integer. Sort by product id.

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.

qtyproduct_id
121
62

Your query result will appear here