oracle数据树形向上汇总?
发布者:陈俊华2019-12-20
with t as ( select 'r1' id, 'r1' pid, null t1, null t2 from dual
union all select 'r2', 'r1', null, null from dual
union all select 'r3', 'r2', 5, 7 from dual
union all select 'r4', 'r2', 10, 20 from dual
)
select id,pid,
(select sum(t1) from t start with id=s.id connect by prior id=pid and id!=pid) t1sum,
(select sum(t2) from t start with id=s.id connect by prior id=pid and id!=pid) t2sum
from t s
order by id
把t as后的子查询换成你的子查询即可