MySQL Forums
Forum List  »  Newbie

Re: Cumulative sum
Posted by: Anthony Willard
Date: November 29, 2006 11:23AM

Assuming that ID is a constant for the order, you could use something like:
SELECT a.id, 
a.in, 
a.out, 
(SELECT SUM( in - out )
  FROM mytable b
  WHERE b.id < a.id) + ( in - out )  AS run_sum
FROM mytable a
ORDER BY id

Anthony

Options: ReplyQuote


Subject
Written By
Posted
November 29, 2006 11:14AM
Re: Cumulative sum
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.