hard · ~12 min
Warehouse operations reconciles physical end-of-period counts (closing_stock) against book inventory derived from opening_stock plus the signed sum of movements, and reports only products that do not balance.
closing_stock
opening_stock
movements
product_id
0
expected_closing = opening_qty + net_movements
discrepancy = closing_qty - expected_closing
discrepancy
expected_closing
closing_qty
Input contract: product_id is unique and non-null in closing_stock (which covers every product to reconcile) and unique and non-null in opening_stock (a subset of products). movement_id is unique and non-null in movements; a product may have zero, one, or many movement rows, and all quantity columns are non-null integers.
movement_id