View Full Version : Aggregate Function?


rschultz
08-27-2001, 06:15 AM
I tried to create the following query:
SELECT Sum([NWT]/2000) AS YTDNWTons, Sum([CTOT]) AS YTDAmount, Count([NWT]) AS [YTDNo of Customers], tblScaleData.Ticket, tblScaleData.PROD
FROM tblScaleData
WHERE (((tblScaleData.Ticket) Like "sc1*") AND ((tblScaleData.PROD)="VEG1" Or (tblScaleData.PROD)="Wood1"));

but I'm getting an error that says:"You tried to execute a query that doesn't include the specified expression 'Ticket' as part of an aggregate function". But 'Ticket' is one of the fields in the table. What does this mean?

Liv Manto
08-27-2001, 07:02 AM
tblScaleData.Ticket, tblScaleData.PROD

If ticket is actually field, you are using it as a table - tblScaleData.Ticket means Field "tblScaleData" is from table "Ticket"

Pat Hartman
08-27-2001, 07:52 AM
You need a group by clause in a totals query:

SELECT Sum(S.[NWT]/2000) AS YTDNWTons, Sum(S.[CTOT]) AS YTDAmount, Count(*) AS [YTDNo of Customers], S.Ticket, S.PROD
FROM tblScaleData As S
WHERE ((S.Ticket Like "sc1*") AND (S.PROD="VEG1" Or S.PROD="Wood1"))
Group by S.Ticket, S.PROD;

rschultz
08-28-2001, 01:36 PM
>>You need a group by clause in a totals query

Ah, that was it. I added a 'Totals' line and put "Expression" in the Expressins columns (interesting how that works<grin> ) and Group in the grouped one and "Where" in the ones that were just plain fields. and it worked.

Thanks