Solved

SQl Calculate running totals on aggregate

Posted on 2008-10-06
5
295 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks again Daniel!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

9 Experts available now in Live!

Get 1:1 Help Now