Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Count nodes and subnodes

max88604Apr 9 2014 — edited Apr 10 2014

Hi ,

Please help in how to do this . I want to extract  hierarchical information along with  count of sub nodes for each node .

Description of Figure 9-1 follows

For Example    1   has 11 sub nodes under it

                       2  has 4

                       3  has 0

                       4 has 2

                        9 has 3

taking the example of employees table i execute this query

select employee_id,

      manager_id

        ,level

       ,LPAD(' ', LEVEL*3) || LAST_NAME AS LAST_NAME,

       sys_connect_by_path (last_name , '/') sys_path_connection

       from employees

       start with manager_id is null

       CONNECT BY PRIOR employee_id = manager_id

       and last_name not in ( 'Kochhar' ,'Raphaely' ,'Weiss','Fripp' , 'Kaufling' , 'Vollman' , 'Mourgos' , 'Russell' , 'Partners'

                              ,'Errazuriz' , 'Cambrault'  ,'Hartstein' );

In this query , how i can get count of all subnodes under a node like under King , it should give me 13, under De Hann it should give me 5

100             1    King                                        /King
102    100    2      De Haan                                       /King/De Haan
103    102    3            Hunold                                          /King/De Haan/Hunold
104    103    4                   Ernst                                             /King/De Haan/Hunold/Ernst
105    103    4                    Austin                                            /King/De Haan/Hunold/Austin
106    103    4                    Pataballa                                        /King/De Haan/Hunold/Pataballa
107    103    4                    Lorentz                                          /King/De Haan/Hunold/Lorentz
149    100    2      Zlotkey                                          /King/Zlotkey
174    149    3         Abel                                              /King/Zlotkey/Abel
175    149    3         Hutton                                           /King/Zlotkey/Hutton
176    149    3         Taylor                                            /King/Zlotkey/Taylor
177    149    3         Livingston                                      /King/Zlotkey/Livingston
178    149    3         Grant                                            /King/Zlotkey/Grant
179    149    3         Johnson                                        /King/Zlotkey/Johnson
This post has been answered by Moazzam on Apr 9 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 8 2014
Added on Apr 9 2014
6 comments
502 views