Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum a value from multible tables 2

Status
Not open for further replies.

heroddaji

Programmer
Aug 22, 2008
10
NL
Hello guys, I need your help with this kind of query
I have 3 table HOURS1, HOURS2, HOURS3, and they have the same colume for every table.
they have column Week,CustomerNr,EmployeeNr,Time.
So what i want is a query that calculate the Total of Time
by every EmployeeNr group by Week And CustomerNr
This is the example

Week CustomerNr EmployeeNr TotalTime (from 3 tables)
---- ---------- ---------- ----------
1 10001 20001 19
1 10001 20002 18
1 10002 20001 17
2 10001 20003 20

SO in every week for every CustomerNr, you get the total time from 3 table for each Employee, I know it may be a little confuse but i believe some experts will help me with this, waiting for you, thax.
 
SELECT Week,CustomerNr,EmployeeNr,Sum([Time]) AS TotalTime
FROM (SELECT Week,CustomerNr,EmployeeNr,[Time] FROM HOURS1
UNION ALL SELECT Week,CustomerNr,EmployeeNr,[Time] FROM HOURS2
UNION ALL SELECT Week,CustomerNr,EmployeeNr,[Time] FROM HOURS3
) AS U
GROUP BY Week,CustomerNr,EmployeeNr

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have 3 table HOURS1, HOURS2, HOURS3, and they have the same colume for every table." Why?? This is not a correct structure in Access. Do you know about normalization?
Have you read:
Fundamentals of Relational Database Design
 
Thanks YOu PHV, u save my life with that magic query

And also thank fneily for your comment, I knew about normalization, but sometime things not so easy....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top