I have this SQL query which calculates total weight:
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;
How I can rewrite it into hierarchical query? Is this possible?
EDIT: Picture of the scheme

The basic query would be like this:
That would give you each individual component and its weight. You could then group and sum in various ways — either by level if you want the sum of the subcomponents’ weights as in your original query, or over everything if you just want a total weight.