Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to find cumulative sum

Author  Topic 

technical
Starting Member

1 Post

Posted - 2009-05-30 : 08:36:48
Hi friends...

I need to find the cumulative total(running total) of a column. i.e. the sum of the field x.Field1 as a seperate column.
NB. The inner Table is set of subqueries.

select x.Field1 from
(
select T.Field1,T.Field2 from Table1 T
)x

The result should be like...

Field1 Cumulative Sum
-----------------------------------
1 1
2 3
3 6
4 10

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-05-30 : 08:45:48
Where do you want to show data?
If you use front end application, do running total there
Otherwise search for Running total+SQL Server in google

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-05-30 : 08:46:05
Is Field1 always without gaps?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-30 : 14:00:17
[code]
SELECT Field1,(SELECT SUM(Field1) FROM Table WHERE Field1<=t.Field1) AS CumulativeSum
FROM Table t
[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-05-30 : 14:40:58
It's either same user or attending same class...
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=126701



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -