Damien Seguy had an interesting observation on my use of self joins for generating rolling sums yesterday:
What about using a user variable to make the rolling sum from the beginning? Something simple enough like this :
set @sum := 159; // to start with the original number of post, or 0 if you prefer. set @mn := 0; // for the month number select @mn := @mn + 1 as MonthNumber Month, Added, @sum := @sum + Added as RunningTotal from ResultListing1;
Damien, of course, is correct, that I could have used a user variable like the above to generate the rolling sum, instead of using a self join. However, there are some complications. First, let's look at what happens if I rewrite Lenz' original GROUP BY statement to include a user variable to calculate running totals:
…[Read more]