Sum the all the above rows of a field on another field in access query

I have an access table with field ID, Item NoofHour this in sequence I like the keep summing the NoofHours
so table Order
id  Item  Hours
1    abc    5
2    ccc    10
3    yyy    2
4   kka     3

I want to make query so result are
id  Item  Hours   Totalhr
1    abc    5             5                
2    ccc    10           15                
3    yyy    2             17
4   kka     3             20

So add the above hours. I will appreciate if somebody can tell me how I can get  sum  of row above.
Thanks
SivasanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul NeralichBusiness OwnerCommented:
Sivasan,

I think you are describing a "running total". Can you share the query that you have written so far?

- Paul N.
0
PatHartmanCommented:
A running total is a trivial process in a report.  You just use the RunningSum() property to create the value.

However, it is much more of a problem in a query and it is also very inefficient and so may be extremely slow.  The most efficient method is to do a self- join and sum all the rows with a PK <= the current one.  This of course only works if you actually have a numeric uniqueID that is ascending.
1
Gustav BrockCIOCommented:
Here is how:

Select *, 
    (Select Sum(Hours) From [Orders] As T 
    Where T.Id <= [Orders].Id) As TotalHours
From [Order]

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

SivasanAuthor Commented:
Hi Gustav Brock,
Thank you very much. This is what I was looking for worked
Thank you
0
Gustav BrockCIOCommented:
You are welcome!
0
PatHartmanCommented:
Thanks for providing the fish Gus just in case the OP couldn't figure out my instructions.
0
Gustav BrockCIOCommented:
You are welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.