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.

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / vinay

Select c1,sum(c2) over (order by c1) as C3 from T1

Is This Answer Correct ?    13 Yes 2 No

Post New Answer

More SQL PLSQL Interview Questions

trans_id trans_date trans_amt debit_credit_indicator 001 01-JAN-13 1099 cr 001 12-JAN-13 500 db 002 24-FEB-13 400 db 002 23-MAR-13 345 cr 001 18-APR-13 800 cr 002 15-MAR-13 600 db 001 12-FEB-13 200 cr i want like this output trans_id trans_date trans_amt debit_credit_indicator 001 JAN 1599 cr no.of trans 2 i want trans_id and trans_date like 'JAN' or 'FEB' etc, trans_amt i want all credit amount - debit amount per each trans_id. and debit_credit_indicator and no.of transactions in a month.

1 Answers   Oracle,


Table name: T1, it has only one column. col1 ------ c b a b b b b d s a a t s Requirement: I need the following output from the above base table by using SQL query. col1 Cnt ----- ------- a 3 b 5 Others 5 Please help. Thanks Guru v.gurus@in.com

11 Answers  


explain the difference between bool, tinyint and bit. : Sql dba

0 Answers  


How does join work in sql?

0 Answers  


Why do we create stored procedures & functions in pl/sql and how are they different?

0 Answers  






What is before and after trigger?

0 Answers  


a. Can you delete data from a View. b. If Yes, can you delete it if there are multiple tables c. If No, can you delete if there is single source table which is joining.

4 Answers   CGI, IBM,


Which is faster count (*) or count 1?

0 Answers  


How does stored procedure reduce network traffic?

0 Answers  


i want to display 1 to 10 numbers using one select statement.

18 Answers   HCL, Nyros, Oracle,


What is a heap in sql?

0 Answers  


Is left join faster than join?

0 Answers  


Categories