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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query one to many tables w/aggregate functions

Status
Not open for further replies.

sandygo

Technical User
Sep 17, 2002
4
US
I have a table called Projects and another table called Project Details. The Projects table contains the overall hours quoted for each project. The Project Details table allows the user to have multiple entries per project and specify hours worked for each entry.

Here's a simplified sample of each:

Projects Table

Project Hours Quoted Service Analyst
12 20 Reporting Sandy

Here's a sample of Project Details Table

Entry Project Hours Worked
1 12 10
2 12 10

When I create a query to group by service type, group by analyst, sum quoted hours and sum hours worked, I get:

40 hours quoted and 20 hours worked. It is duplicating the quoted hours for every entry in Project Details. What I want is 20 hours quoted and 20 hours worked.

Any help is appreciated.

Thanks
 
Why are you summing hoursQuoted?

select hoursQuoted,service,analyst,sum(hours)
from projects p inner join projectDetails pd
on p.project = pd.project
group by hoursQuoted,service,analyst
 
Swamp Boogie,

Thanks for you response, still not working.

I tried grouping by Hours quoted. Problem is it groups by the value in Hours Quoted. For instance, I have three projects with a Service Type of Reporting, each has 1 Hours Quoted. When I group by Analyst, by Service Type, the result is 1 hours quoted for the Service Type of Reporting. Should be 3.

The inner join is set up as you specified.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top