Chained sum

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I´ve got one question. Is there any posibility to make chained data values?
For example, I´ve got fíve values, which means increase in value in time
5
0
8
4
7

and I want to create a sum between them. Especialy the sum will change only
if there will be increasing or decreasing in value (not 0).For example it
should look like this:
5
5
0
5
8
13
4
17
7
24

Is there any function which could help?

Thanks
Jan
 
That is a running sum. Unfortunately for you, the records MAY MOVE,
relatively among themselves, as data pages are split, or as the database is
compacted. You need another column supplying the ordering, such as a
dateStamp, as example.


SELECT a.dateStamp,
SUM(a.data) As AmountForThisDay,
SUM(b.data) As upToIncludingNow

FROM myTable AS a INNER JOIN myTable AS b
ON a.dateStamp >= b.dateStamp

GROUP BY a.dateStamp
ORDER BY a.dateStamp ASC



should do.



Hoping it may help,
Vanderghast, Access MVP
 
Back
Top