SQl Calculate running totals on aggregate

In SQL How do I calculate the running totals on a field straight after (ie withingt the same sql function) it has been summed or counted. See attached example

test.xls
ulsterweaversAsked:
Who is Participating?
 
Daniel WilsonConnect With a Mentor Commented:
At the bottom of my reply should be the Accept link.

glad to help ... I've fought w/ that type of problem enough that now I know the answer!
0
 
Daniel WilsonCommented:
Would be nicer in SQL Server ... but I think this will work in Access.

Select M.Booked, Sum(M.Moved) as Qty, 
  (Select Sum(Booked) From Moves Where Moves.Booked <= M.Booked) as Res
From Moves as M 
Group by M.booked
order by M.Booked

Open in new window

0
 
ulsterweaversAuthor Commented:
Yeah that's the one Daniel. Thank-you very much. Cant believe I was being so daft, I was using count (becase the moved was only going up or down by one each time) and always being slightly out, which made me question everything!!
0
 
ulsterweaversAuthor Commented:
oh its not giving me the option to accept and award points, is it because I posted a reply first? do you need to repost?
0
 
ulsterweaversAuthor Commented:
thanks again Daniel!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.