没有看懂结果是如何得来的。。。
with tmp as (
select 1 as ID, 0 as ParentID, 66 as Amount from dual union all
select 2 as ID, 1 as ParentID, 23 as Amount from dual union all
select 3 as ID, 1 as ParentID, 37 as Amount from dual union all
select 4 as ID, 2 as ParentID, 11 as Amount from dual union all
select 5 as ID, 2 as ParentID, 15 as Amount from dual
)
select
a.id,
a.parentid,
a.amount,
sum(case when b.parentid is null then a.amount else b.amount end) as 求和
from tmp a
left join tmp b on a.id=b.parentid
group by a.id,a.parentid,a.amount