View Full Version : Sums in a Query


sara82
10-13-2005, 07:58 AM
I have a query which shows employee Totals it has the following fields:

Emp: [EmployeeLastName] & ", " & [EmployeeFirstName]

LogHours
Total: Sum

TotalWorkedPgs
Total: Sum

WorkDays: Sum([LogHours])/8

AvgPgs: (Sum([TotalWorkedPgs]))/(Sum([LogHours])/8)

JobType

JobEffort

-----

Job Effort is a has 3 values: My Corrections, Others, YOYO

I would like to know the:
Sum of TotalWorkedPgs when Job Effort is My Corrections
Sum of TotalWorkedPgs when Job Effort is Others
Sum of TotalWorkedPgs when Job Effort is YOYO

Because I need all of this information on a report.

Any help will be appreciated.

Thanks

Pat Hartman
10-13-2005, 08:55 PM
Rather than summarizing data in the query, summarize it in the report.

When you create a totals query, each field in the Select clause requires aggregation. Now that aggregation might be in the group by or it might be with a sum(), avg(), or other function. So if you want to aggregate something by something else:
Select something, Sum(something else) as MySum
From yourTable
Group by something;

sara82
10-14-2005, 05:34 AM
Thank you Pat I will try your suggestion right now and let you know how it goes.

sara82
10-14-2005, 06:18 AM
I'm sorry Pat, but I'm not able to recreate the example that you provided me.

If I needed something like this: Job Effort "My Corrections", Sum(TotalWorkedPgs)
I know that is not the right syntax as I don't know how to put it in the correct syntax.

How would I do this in Design View of the query

Pat Hartman
10-14-2005, 01:45 PM
Select JobEffort, Sum(TotalWorkedPgs) As SumWorkedPgs
From YourTable
Group by JobEffort;

This query will return one row for each distinct value of JobEffort along with the sum of TotalWorkedPgs for that JobEffort.

sara82
10-17-2005, 08:23 AM
Thank you Pat, it's what I needed