Running Total Query in Oracle

Posted on 2003-12-02
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:

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
1   100   100
2   100   200
3   50    250
4   25    275

etc, etc.

Any ideas?
Question by:markag
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

Accepted Solution

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

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

Expert Comment

ID: 9860191
How about:

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

Expert Comment

ID: 9866362
Try this:

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

Love Analytics...


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: 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…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

734 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