Solved

SQl Calculate running totals on aggregate

Posted on 2008-10-06
5
308 Views
Last Modified: 2011-10-19
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
0
Comment
Question by:ulsterweavers
  • 3
  • 2
5 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 22649802
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
 

Author Comment

by:ulsterweavers
ID: 22650322
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
 

Author Comment

by:ulsterweavers
ID: 22650356
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
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 125 total points
ID: 22650368
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
 

Author Closing Comment

by:ulsterweavers
ID: 31503383
thanks again Daniel!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now