17,086
社区成员
发帖
与我相关
我的任务
分享
select * from emp;
with t as(
select '总分类' "对象名称",'123' id,'b' parent_id,null 数量 from dual
union all
select '分类1','4','123',null from dual
union all
select '分类11','5','123',null from dual
union all
select 'A','0','5',100 from dual
union all
select 'B','0','5',100 from dual
union all
select 'C','0','5',200 from dual
union all
select '分类12','6','123',NULL from dual
union all
select 'A','0','6',100 from dual
union all
select 'B','0','6',200 from dual
)
select t.对象名称,t.id,t.parent_id,
(select sum(数量)
from t t1
start with 对象名称 = t.对象名称
and t1.parent_id = t.parent_id
connect by prior id = parent_id) s
from t;
对象名称 ID PARENT_ID S
-------- --- --------- ----------
总分类 123 b 700
分类1 4 123
分类11 5 123 400
A 0 5 100
B 0 5 100
C 0 5 200
分类12 6 123 300
A 0 6 100
B 0 6 200
9 rows selected