i have a table like this. i want to output like this
c1 c2 c1 c2

1 10 1 10
2 20 2 30
3 30 3 60
4 40 4 100
5 5 5 105

c1 and c2 are columns in a table .i want output like this

c2 values are 10,10+20,10+20+30,10+20+30+40.10+20+30+40+5.

write a sql query.pls help this
i want urgent.

Answer Posted / prativa mishra

select t.c1,
(SELECT SUM(x.c2)
FROM table_name x
where x.c1 <= t.c1) as c2
from new table_name


or

select c1,
SUM(SUM(c2)) OVER
(ORDER BY c1 ROWS BETWEEN UNBOUNDED PRECEDING AND
CURRENT ROW)
AS C2
from table_name
group by c1

Is This Answer Correct ?    17 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how do you control the max size of a heap table? : Sql dba

550


What are stuff and replace function?

582


What are the different dml commands in sql?

595


What is union and union all keyword in sql?

574


What is aggregate function in sql?

549






How do you write a complex sql query?

599


What is the difference between inner join and natural join?

519


What is procedure in pl sql?

542


What are inbuilt functions in sql?

608


How do you update a table in sql?

524


How much does sql cost?

534


What is left join in postgresql?

547


Does truncate release storage space?

568


What are the types of variables use in pl sql?

519


How do we use distinct statement? What is its use?

564