Home » RDBMS Server » Server Administration » Running Sum In query
Running Sum In query [message #372860] Wed, 14 March 2001 13:13 Go to next message
Hari
Messages: 59
Registered: August 2000
Member
My data
Period Value.
1 2000
2 4500
3 5000
4 3200
5 2000

I need a select statement to select period,value, value1( which is running sum sof value).

The result of query should be as follows
Period Value. Running_Value
1 2000 2000
2 4500 6500
3 5000 11500
4 3500 15000
5 2000 17000
Re: Running Sum In query [message #372861 is a reply to message #372860] Wed, 14 March 2001 14:35 Go to previous messageGo to next message
Joachim Lindner
Messages: 30
Registered: February 2001
Member
Hi Hari,
do me a facour an check this statement. Unfortunlately I have no Oracle available, here.
It should solve your problem. It's doing that, at least in my mind :-)

select t1.period, t1.value, sum(t2.value)
from mytab t1, mytab t2
where t1.period >= t2.period
group by t1.period, t1.value;
Re: Running Sum In query (addon) [message #372865 is a reply to message #372860] Wed, 14 March 2001 15:12 Go to previous messageGo to next message
Joachim Lindner
Messages: 30
Registered: February 2001
Member
I think I missed an
order by t1.period asc

Cheers, Joachim
Re: Running Sum In query [message #372869 is a reply to message #372860] Wed, 14 March 2001 23:49 Go to previous messageGo to next message
Balamurugan.R
Messages: 91
Registered: March 2001
Member
hai hari,

It is not possible in sql querey, it can be

easily done in pl/sql. I think u know that, if u

want help in pl/sql definetely i will help u
Re: Running Sum In query [message #372876 is a reply to message #372860] Thu, 15 March 2001 04:34 Go to previous messageGo to next message
Joachim Lindner
Messages: 30
Registered: February 2001
Member
Sorry Balu,
you're wrong. Just checked my SQL and it works perfectly.
Re: Running Sum In query [message #372878 is a reply to message #372869] Thu, 15 March 2001 07:12 Go to previous messageGo to next message
balu
Messages: 23
Registered: March 2001
Junior Member
Hai joachim,

your query is correct when u have two tables,

but the question is only one table,

Table name:t1
a b
-------
1 2000
2 4000
3 6000
4 8000
5 10000

The output should be
a b sum(b)
------------
1 2000 2000
2 4000 6000
3 6000 12000
4 8000 18000
5 10000 28000

So if u know the query for this table, please give it. Although your query is correct if i have
two tables, but this is only one table.
Re: Running Sum In query [message #372880 is a reply to message #372878] Thu, 15 March 2001 08:01 Go to previous messageGo to next message
Martin
Messages: 83
Registered: February 2000
Member
Balu,

Joachim's query *is* on a single table. The main idea behind it is the self join.
Re: Running Sum In query [message #372883 is a reply to message #372869] Thu, 15 March 2001 10:36 Go to previous message
Hari
Messages: 59
Registered: August 2000
Member
hi balu and Joachim Lindner
The query works fine . Using PL/SQl is not probs i have done that.
I wnated to know if you both have come across any new analytical functions of oracle 8 or 8i

Thanks
HAri
Previous Topic: Could you help me?
Next Topic: Need Help on a complex SQL to eliminate data
Goto Forum:
  


Current Time: Sat Jun 01 17:22:17 CDT 2024