oracle树状起点终点,树状查询是否可以获取到起始节点并分组解决办法
SQL codewith tbl as(select 13 as id, 10 as mgrid, 2 as ilevel, 100 as blance from dualunion allselect 41 as id, 13 as mgrid, 3 as ilevel, 100 as blance from dualunion allselect 42 as id, 13 as mgrid,
SQL codewith tbl as
(
select 13 as id, 10 as mgrid, 2 as ilevel, 100 as blance from dual
union all
select 41 as id, 13 as mgrid, 3 as ilevel, 100 as blance from dual
union all
select 42 as id, 13 as mgrid, 3 as ilevel, 100 as blance from dual
union all
select 43 as id, 13 as mgrid, 3 as ilevel, 100 as blance from dual
union all
select 14 as id, 10 as mgrid, 2 as ilevel, 100 as blance from dual
union all
select 44 as id, 14 as mgrid, 3 as ilevel, 100 as blance from dual
union all
select 45 as id, 14 as mgrid, 3 as ilevel, 100 as blance from dual
)
select id, sum(blance) as blance
from (select connect_by_root id as id, blance
from tbl
start with ilevel = 2
connect by prior id = mgrid) t
group by id;
ID BLANCE
---------- ----------
13 400
14 300
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)