Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Running Total Query in Oracle

Posted on 2003-12-02
3
Medium Priority
?
855 Views
Last Modified: 2008-03-17
8i, Standard, no Analytic functions available....

I need to calculate a running total column which would be the sum of a column for all preceding rows including the current row. for example, if my data was:

ID VAL
1   100
2   100
3   50
4  25

and I was doing a running total on VAL, Ordered By ID, then my result set would be
ID VAL RUNNING_TOTAL
1   100   100
2   100   200
3   50    250
4   25    275

etc, etc.

Any ideas?
0
Comment
Question by:markag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
IanBlundell earned 1500 total points
ID: 9860177
Given a table called exp_test, try something like this:

select      it1.id
,            it1.val
,            (select      sum(it2.val)
             from      exp_test it2
             where      it2.id <= it1.id)            
from exp_test it1
0
 
LVL 15

Expert Comment

by:andrewst
ID: 9860191
How about:

select id, val, (select sum(val) from mytable t2 where t2.id <= t1.id) running_total
from mytable t1
order by id;
0
 
LVL 13

Expert Comment

by:riazpk
ID: 9866362
Try this:


select id,val, sum(val) over (order by id) Running_Total
from mytable
order by id
/



Love Analytics...


Riaz
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question