select t.item_code,t.sum_q+nvl(p.sum_q,0) as sum_quantity,
(case when p.sum_q is null then 'N' else 'Y') end as flag
from (select item_code,sum(quantity) as sum_q from A group by item_code) t
left join (select item_code,sum(quantity) as sum_q from B group by item_code) p
on t.item_code=p.item_code
;