Skip to content
Advertisement

finding sum of salary from employee table

I’m having the data in data base like in the below.

Emp_id Ename Sal 
11      AAA   10
22      BBB   20
33      CCC   30
44      DDD   60

Then i want to populate a new column as in the below.

Emp_id Ename Sal  New_column
11      AAA   10    10  --> 10+0
22      BBB   20    30  --> 10+20
33      CCC   30    60  --> 10+20+30
44      DDD   60    120 --> 10+20+30+60

Thank you for the help in adavance!

Advertisement

Answer

If you can use Window analytic function within your DBMS, then use :

select t.*, sum(sal) over (order by emp_id) as New_column 
  from tab t
 order by emp_id 
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement