sql - Executing Hierarchical Query showing all data -
i trying hierarchical select
query in oracle can't desire out put there , don't under stand writing wrong query or there wrong data in table desire out put like
i_id name mgr_id level path 1 smith 0 0 /smith 2 allen 1 1 /smith/allen 3 ward 1 1 /smith/ward 5 martin 1 1 /smith/martin 4 jones 2 2 /smith/allen/jones 7 clark 2 2 /smith/allen/clark 6 blake 3 2 /smith/ward/blake 8 scott 7 3 /smith/allen/clark/scott 9 king 7 3 /smith/allen/clark/king 10 turner 8 4 /smith/allen/clark/scott/turner 12 james 8 4 /smith/allen/clark/scott/james 11 adams 10 5 /smith/allen/clark/scott/turner/adams 13 ford 11 6 /smith/allen/clark/scott/turner/adams/ford 14 miller 13 7 /smith/allen/clark/scott/turner/adams/ford/miller
please me out reference please check
i used query similar yours, , grouped result select 1 row max level each i_ids.
query:
select * ( select i_id, name, mgr_id, max(plevel) - 1 "level", max(path) keep (dense_rank last order plevel) path ( select i_id, name, mgr_id, level plevel, sys_connect_by_path(name, '/') path emp connect prior i_id = mgr_id ) group i_id, name, mgr_id ) order "level", i_id
| i_id | name | mgr_id | level |path | |------|--------|--------|-------|--------------------------------------------------| | 1 | smith | 0 | 0 |/smith | | 2 | allen | 1 | 1 |/smith/allen | | 3 | ward | 1 | 1 |/smith/ward | | 5 | martin | 1 | 1 |/smith/martin | | 4 | jones | 2 | 2 |/smith/allen/jones | | 6 | blake | 3 | 2 |/smith/ward/blake | | 7 | clark | 2 | 2 |/smith/allen/clark | | 8 | scott | 7 | 3 |/smith/allen/clark/scott | | 9 | king | 7 | 3 |/smith/allen/clark/king | | 10 | turner | 8 | 4 |/smith/allen/clark/scott/turner | | 12 | james | 8 | 4 |/smith/allen/clark/scott/james | | 11 | adams | 10 | 5 |/smith/allen/clark/scott/turner/adams | | 13 | ford | 11 | 6 |/smith/allen/clark/scott/turner/adams/ford | | 14 | miller | 13 | 7 |/smith/allen/clark/scott/turner/adams/ford/miller |
Comments
Post a Comment