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!

calculating sum(salary) up or down the hierarchy

45736May 14 2010 — edited May 18 2010

Greetings All,

How to get total salary rolled up from lowest level to higher level of the hierarchy?

We can get the employee hierarchy and salary from hr.employees table using following query:

select level, last_name, salary
from hr.employees
start with employee_id = (select employee_id
                                     from  hr.employees
                                     where manager_id IS NULL
                                    )
connect by prior employee_id  = manager_id

How to get the salary rolled up to higher level with sql as follows?

level      last_name        salary        total salary

2         Kochhar           17000          109800
3         Whalen              4400            4400
3         Mavris                6500            6500
3         Bae                 10000           10000
3         Higgins             12000          20300
4             Gietz              8300           8300
3 	   Greenberg        12000          51600
4 	      Faviet             9000            9000
4 	      Chen              8200            8200
4 	      Sciarra            7700             7700
4 	      Urman            7800             7800
4 	      Popp              6900             6900 

Here all level 4 under level 3 Greenberg rolled up to level 3, then level 4 under Higgins rolled up to level 3, then all level 3 under Kochar rolled up to level 2.

Can this be done in sql?

Thanks for your help.

Edited by: rxshah on May 14, 2010 3:45 AM

This post has been answered by 678284 on May 14 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2010
Added on May 14 2010
2 comments
1,052 views