Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Summing hierarchical data SQL
Michel Cadot schrieb:
> "Mike C" <michaeljc70_at_hotmail.com> a écrit dans le message de news: 1159993002.453179.263340_at_e3g2000cwe.googlegroups.com...
>
> Mike C wrote:
>> Michel Cadot wrote: >>> "Mike C" <michaeljc70_at_hotmail.com> a écrit dans le message de news: 1159989707.458848.89750_at_c28g2000cwb.googlegroups.com... >>> I've already used the connect by to get the data in this format.... >>> >>> ----------------------- >>> >>> - Don't top post >>> - So go on, you can easely get the sum over the hierarchy with a connect by. >>> >>> Regards >>> Michel Cadot >> This doesn't really need a CONNECT BY as it only needs to look at 1 >> level below. To get the sum for level 1, it only needs to look at >> level 2, etc. If I could "easily get the sum" I would have done it and >> wouldn't have posted to the group!
SELECT Empno,
Ename, Sal + Nvl((SELECT SUM(Sal) FROM Scott.Emp i CONNECT BY PRIOR Empno = Mgr START WITH o.Empno = i.Mgr), 0) Total_SubTree_Sal
Not sure, about the performance with correlated hierarchical subquery, whereas with not too big volumes of data ( and not too deep hierarchy) should be ok.
It might be interesting, if this result can be achieved without correlated subquery however...
Best regards
Maxim Received on Thu Oct 05 2006 - 03:35:07 CDT