MySQL Forums
Forum List  »  Newbie

Cumulative sum
Posted by: João Mota
Date: November 29, 2006 11:14AM

I have a table like this

id in out
---------------
1 5 0
2 0 6
3 2 0
4 3 0
5 0 4


And would like a query that would return the cumulative sum for each record as:
sum = "sum from the previous record" + in - out

Like this:

id in out sum
---------------------
1 5 0 5
2 0 6 -1
3 2 0 1
4 3 0 4
5 0 4 0

Can someone help me with this?

Options: ReplyQuote


Subject
Written By
Posted
Cumulative sum
November 29, 2006 11:14AM
November 29, 2006 11:23AM
November 29, 2006 11:48AM
December 04, 2007 04:54PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.