SELECT PS_CM_DEPLETE.BUSINESS_UNIT , PS_CM_DEPLETE.INV_ITEM_ID , PS_CM_DEPLETE.CM_BOOK , PS_CM_DEPLETE.CM_DT_TIMESTAMP , PS_CM_DEPLETE.CM_SEQ_NBR , PS_CM_RECEIPTS.CM_DT_TIMESTAMP_A , PS_CM_RECEIPTS.CM_SEQ_NBR_A , PS_CM_RECEIPTS.QTY_BASE , SUM(PS_CM_DEPLETE.QTY_BASE) , PS_CM_RECEIPTS.QTY_BASE - SUM(PS_CM_DEPLETE.QTY_BASE) FROM PS_CM_RECEIPTS , PS_CM_DEPLETE WHERE PS_CM_RECEIPTS.BUSINESS_UNIT = PS_CM_DEPLETE.BUSINESS_UNIT AND PS_CM_RECEIPTS.INV_ITEM_ID = PS_CM_DEPLETE.INV_ITEM_ID AND PS_CM_RECEIPTS.CM_BOOK = PS_CM_DEPLETE.CM_BOOK AND PS_CM_RECEIPTS.DT_TIMESTAMP = PS_CM_DEPLETE.CM_DT_TIMESTAMP AND PS_CM_RECEIPTS.SEQ_NBR = PS_CM_DEPLETE.CM_SEQ_NBR AND PS_CM_RECEIPTS.CM_DT_TIMESTAMP_A = PS_CM_DEPLETE.CM_DT_TIMESTAMP_A AND PS_CM_RECEIPTS.CM_SEQ_NBR_A = PS_CM_DEPLETE.CM_SEQ_NBR_A AND EXISTS ( SELECT 'X' FROM PS_CM_RECEIPT_COST WHERE PS_CM_RECEIPTS.BUSINESS_UNIT = PS_CM_RECEIPT_COST.BUSINESS_UNIT AND PS_CM_RECEIPTS.INV_ITEM_ID = PS_CM_RECEIPT_COST.INV_ITEM_ID AND PS_CM_RECEIPTS.CM_BOOK = PS_CM_RECEIPT_COST.CM_BOOK AND PS_CM_RECEIPTS.DT_TIMESTAMP = PS_CM_RECEIPT_COST.DT_TIMESTAMP AND PS_CM_RECEIPTS.SEQ_NBR = PS_CM_RECEIPT_COST.SEQ_NBR AND PS_CM_RECEIPTS.CM_DT_TIMESTAMP_A = PS_CM_RECEIPT_COST.CM_DT_TIMESTAMP_A AND PS_CM_RECEIPTS.CM_SEQ_NBR_A = PS_CM_RECEIPT_COST.CM_SEQ_NBR_A) AND PS_CM_RECEIPTS.CONSIGNED_FLAG = 'N' AND PS_CM_DEPLETE.CONSIGNED_FLAG = 'N' AND (PS_CM_DEPLETE.POSTED_FLAG IN ('Y','X') OR PS_CM_DEPLETE.TRANSACTION_GROUP = '060') GROUP BY PS_CM_DEPLETE.BUSINESS_UNIT, PS_CM_DEPLETE.INV_ITEM_ID, PS_CM_DEPLETE.CM_BOOK, PS_CM_DEPLETE.CM_DT_TIMESTAMP, PS_CM_DEPLETE.CM_SEQ_NBR, PS_CM_RECEIPTS.CM_DT_TIMESTAMP_A , PS_CM_RECEIPTS.CM_SEQ_NBR_A, PS_CM_RECEIPTS.QTY_BASE
|