[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Calculate sum in a query

Posted on 2014-04-22
2
Medium Priority
?
177 Views
Last Modified: 2014-04-22
Hello experts - hope you can help with this little question.

I have 3 tables – tblClients, tblJobs and tblJobVolLink.

The relationships are:
One to Many - Clients to Jobs
Many to Many – Jobs to Volunteers

The following query:
SELECT tblClients.[Client ID], tblJobs.[Short description], tblJobVolLink.HoursWorked
FROM (tblClients INNER JOIN tblJobs ON tblClients.[Client ID] = tblJobs.[Client ID]) INNER JOIN tblJobVolLink ON tblJobs.[Job ID] = tblJobVolLink.[Job ID];

Returns a row for every volunteer, with their separate hours – eg:
ID       Description     Hours
23          Job 1                   2
23          Job 1                   3
.....

What I require is for the query to return a single row for each Job with the TOTAL volunteer hours – eg:
ID      Description      Hours
23       Job 1                 5
.....

Can you please suggest the SQL that would give me that.

Regards

Richard
0
Comment
Question by:rltomalin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
Dulton earned 2000 total points
ID: 40014976
SELECT tblClients.[Client ID], tblJobs.[Short description], Sum(tblJobVolLink.HoursWorked) As [HrsWorked]
FROM (tblClients INNER JOIN tblJobs ON tblClients.[Client ID] = tblJobs.[Client ID]) INNER JOIN tblJobVolLink ON tblJobs.[Job ID] = tblJobVolLink.[Job ID]
group by  tblClients.[Client ID], tblJobs.[Short description];

Open in new window

0
 

Author Closing Comment

by:rltomalin
ID: 40015029
Wow - that did it!!

Thanks Dulton

Regards

Richard
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

650 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