PO在途

select PO_NUMBER,org_id,sum(quantity) from
(SELECT /*INDEX(RT RCV_TRANSACTIONS_N26)*/
       PHA.SEGMENT1 PO_NUMBER,
       PHA.ORG_ID,
       decode(rt.transaction_type,'DELIVER',-rt.quantity,'RETURN TO VENDOR',-rt.quantity,rt.quantity) quantity
  FROM RCV_TRANSACTIONS      RT,
       PO_HEADERS_ALL        PHA
 WHERE RT.PO_HEADER_ID = PHA.PO_HEADER_ID
   AND PHA.ORG_ID = 218
   AND rt.transaction_type in ('RECEIVE','DELIVER','RETURN TO VENDOR','CORRECT'))
HAVING sum(quantity)>0
group by po_number,org_id

你可能感兴趣的:(oracle,pl/sql)