根据子节点的金额向上汇总所有父节点的金额

with test(fid, fname, fparentid, fmoney) as (
values('01', 'test01', '0', 0)
union
values('0101', 'test0101', '01', 0)
union
values('010101', 'test010101', '0101', 10)
union
values('010102', 'test010102', '0101', 20)
union
values('0102', 'test0102', '01', 200)
union
values('02', 'test02', '0', 2000)
),
temp(fid, fname, fparentid, fmoney) as (
select fid, fname, fparentid, fmoney from test
union all
select parent.fid, parent.fname, parent.fparentid, child.fmoney from temp as child, test as parent where child.fparentid = parent.fid
)
select fid, fname, sum(fmoney) as fmoney from temp group by fid, fname
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值