
PUZZLE 35 INVENTORY ADJUSTMENTS 145
PUZZLE
35
INVENTORY ADJUSTMENTS
This puzzle is a quickie in SQL-92, but was very hard to do in SQL-89.
Suppose you are in charge of the company inventory. You get
requisitions that tell how many widgets people are putting into or taking
out of a warehouse bin on a given date. Sometimes the quantity is
positive (returns), and sometimes the quantity is negative (withdrawals).
CREATE TABLE InventoryAdjustments
(req_date DATE NOT NULL,
req_qty INTEGER NOT NULL
CHECK (req_qty <> 0),
PRIMARY KEY (req_date, req_qty));
Your job is to provide a running balance on the quantity-on-hand as
an SQL column. Your results should ...