Solved

Calculate sum in a query

Posted on 2014-04-22
2
174 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 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

707 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