総重量を計算する次の SQL クエリがあります。
select c.componentid, nvl(cs.weightkg, 0) as componentkg,
(case
when exists (select 1 from component where fkcomponentid = c.componentid) then
(select sum(nvl(cs.weightkg, 0)) as kg FROM component a, componentstats cs where a.fkcomponentid is not null and cs.componentstatsid = a.componentstatsid and a.fkcomponentid = c.componentid)
end) as childrenkg
from component c, componentstats cs
where
cs.componentstatsid = c.componentstatsid
and componentid = ?
order by c.componentid;
階層クエリに書き直すにはどうすればよいですか? これは可能ですか?
編集:スキームの写真