假如有生產入庫退回時
不能用負數拋入
會造成一正一負
要先找出原先拋入的生產入庫
找出已存在的入庫資料
TRX_ID,TRANSACTION_DATE
8607,2018/7/25 下午 04:05:12
18504,2018/7/25 下午 04:15:08
TRX_ID,ORGANIZATION_CODE,BATCH_NO,ITEM_NO,LOT_NUMBER,TRANSACTION_QUANTITY,TRANSACTION_UOM,
SUBINVENTORY_CODE,TRANSACTION_DATE,
ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5,ATTRIBUTE6,
ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,
STATUS,STATUS_MESSAGE,CREATION_DATE,CREATION_BY_NAME,
ERP_UPDATE_DATE,REQUEST_ID,ORGANIZATION_ID,INVENTORY_ITEM_ID,BATCH_ID,OPRN_NO
-----------------------
8607,TH1,5212018012202,4B1-7A0353-A51002,171215312-T17112001,-7,PCS,
1308,2018/7/25 下午 04:05:12,
D322018012216Q,,1,3,2,,0,-80,kg,P0821A,,E,,
2018/1/22,,2018/7/25 下午 04:51:22,1553024,121,8248,2231,5502
18504,TH1,5162018020803,4B1-D00302-T51004,180207513-A18020411,-300,PCS,
1208,2018/7/25 下午 04:15:08,
D322018021012Q,D001,1,5,3,,0,230.15,kg,,,S,,2018/2/10,,
2018/7/25 下午 06:04:53,1553167,121,9146,4640,5501
SELECT ROW_NUMBER() OVER(PARTITION BY
MMT.TRANSACTION_SOURCE_ID,
MMT.INVENTORY_ITEM_ID,
MTL.LOT_NUMBER
ORDER BY
MTL.TRANSACTION_QUANTITY DESC) ROW_NUM,
-- 以上先將同一 Source + Item + Lot 並列 並依據數量排序
MMT.TRANSACTION_SOURCE_ID,
MMT.INVENTORY_ITEM_ID,
MTL.LOT_NUMBER,
MMT.TRANSACTION_ID,
MMT.ORGANIZATION_ID,
MMT.TRANSACTION_DATE,
--ABS(IN_TRANSACTION_QUANTITY) START_QUANTITY,
MTL.TRANSACTION_QUANTITY QUANTITY_ISSUED,
MT.TRANSACTION_TYPE_NAME
FROM APPS.MTL_MATERIAL_TRANSACTIONS MMT,
APPS.MTL_TRANSACTION_LOT_NUMBERS MTL,
APPS.MTL_TRANSACTION_TYPES MT
WHERE 1 = 1
AND MMT.TRANSACTION_TYPE_ID = MT.TRANSACTION_TYPE_ID
AND MT.TRANSACTION_TYPE_NAME LIKE 'WIP%Completion'
AND MTL.TRANSACTION_ID = MMT.TRANSACTION_ID
AND MMT.TRANSACTION_SOURCE_ID = IN_BATCH_ID
AND MMT.INVENTORY_ITEM_ID = IN_ITEM_ID
AND MTL.LOT_NUMBER = IN_LOT_NUMBER
AND MMT.SUBINVENTORY_CODE = IN_SUBINV_CODE
不分料號的前一個日期
SELECT product_id, order_date, LAG (order_date,1) OVER (ORDER BY order_date) AS prev_order_date FROM orders;要分的前一個日期
SELECT product_id, order_date, LAG (order_date,1) OVER (PARTITION BY product_id ORDER BY order_date) AS prev_order_date FROM orders;