select polt.order_no PO_NUMBER,
polt.line_no,
polt.original_qty ORD_QTY,
sum(prt.qty_arrived) ARRIVED
from purchase_order_line_tab polt
inner join purchase_order_tab pot
on pot.order_no = polt.order_no
left outer join PURCHASE_RECEIPT_TAB prt
on (prt.order_no = pot.order_no and polt.line_no = prt.line_no)
where polt.order_no in ('28','29')
and pot.rowstate <> 'Planned'
and NVL(prt.rowstate, 'NC') <> 'Cancelled'
GROUP BY polt.order_no, polt.line_no, polt.original_qty;
|