我有这个计算总重量的 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;
我如何将其重写为分层查询?这可能吗?
编辑:该计划的图片