oracle存储过程实现两张表多条数据对多条数据的相减操作,并伴有两张表的更新,已经第三张中间表的插入.

2025-01-13 14:05:50
推荐回答(1个)
回答1:

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
;