June 2, 2011 at 7:00 am
I need to know the logic / sql to achieve cumulative sum or running total ?
Please give a minimal code to achieve this which is easily understandable.
CITY_ID STATE_ID CITY_NAME DATA Cumulative Sum
1 2 Ohio 100 100
2 1 Las Vegas 200 300
3 1 Carson City 300 600
4 4 Helena 900 1500
5 4 Billings 700 2200
6 5 Austin 1100 3300
7 2 Cleveland 2000 5300
thanks in advance ...
June 2, 2011 at 7:06 am
Read Jeff Moden's article here[/url]. It will walk you through the whole process. It is lengthy but incredibly informative.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 2, 2011 at 7:07 am
Please see the article below written by Jeff Moden on running totals...
June 2, 2011 at 7:10 am
thanks a lot will go thru that ...
June 2, 2011 at 7:10 am
June 2, 2011 at 7:12 am
Sriram.RM (6/2/2011)
same article quoted by 2 people with a time difference of one min!!!
Proof that the article rocks huh!!!
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply