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

What is sql stand for?

579


What is PL/SQL Records?

631


how can we know the number of days between two given dates using mysql? : Sql dba

550


What are the parts of a sql statement?

559


What is sql entity?

536






Is it mandatory for the primary key to be given a value when a new record is inserted?

713


How can you maintain the integrity of your database on instances where deleting an element in a table result in the deletion of the element(s) within another table?

669


What view means?

558


How can you get sql*loader to commit only at the end of the load file? : aql loader

556


what are the properties and different types of sub-queries? : Sql dba

510


What is sharding in sql?

568


What are the types of views in sql?

546


what is foreign key? : Sql dba

591


what is a database? : Sql dba

612


What are the different types of joins in sql?

585