Настройка на схема на Oracle 11g R2 :
CREATE TABLE lots ( Lot_Size, Reported_QTY ) AS SELECT 150, 100 FROM DUALUNION ALL SELECT 150, 100 FROM DUALUNION ALL SELECT 150, 80 FROM DUALUNION ALL SELECT 150, 80 FROM DUALUNION ALL SELECT 150, 5 FROM DUAL;
Заявка 1 :
SELECT Lot_Size, Reported_QTY, COALESCE( LAG( Reported_QTY) OVER (ORDER BY NULL) - Reported_QTY, Lot_Size - Reported_QTY ) AS Qty_BalanceFROM Lots
<предварителен код>| LOT_SIZE | REPORTED_QTY | КОЛИЧЕСТВО_БАЛАНС ||----------|--------------|-------------|| 150 | 100 | 50 || 150 | 100 | 0 || 150 | 80 | 20 || 150 | 80 | 0 || 150 | 5 | 75 |