I am attempting to build a query that will give the score of the last inspection for each active facility. So far I have this sql:
SELECT Food.FacilityID, Inspections.InspectionDate, Inspections.TypeID, Food.Status, 100-Sum(violation.wt) AS Score
FROM ((Inspections INNER JOIN Food ON Inspections.FacilityID=Food.FacilityID) LEFT JOIN InspectionDetails ON Inspections.InspectionID=InspectionDetails.InspectionID) LEFT JOIN Violation ON InspectionDetails.ViolationID=Violation.ViolationID
WHERE (((Inspections.TypeID)=2) AND ((Food.Status)="active"));
when I run it, I get this error:
"You tried to execute a query that does not include the specific expression 'FacilityID' as part of an aggregate function."
What am I doing wrong?
SELECT Food.FacilityID, Inspections.InspectionDate, Inspections.TypeID, Food.Status, 100-Sum(violation.wt) AS Score
FROM ((Inspections INNER JOIN Food ON Inspections.FacilityID=Food.FacilityID) LEFT JOIN InspectionDetails ON Inspections.InspectionID=InspectionDetails.InspectionID) LEFT JOIN Violation ON InspectionDetails.ViolationID=Violation.ViolationID
WHERE (((Inspections.TypeID)=2) AND ((Food.Status)="active"));
when I run it, I get this error:
"You tried to execute a query that does not include the specific expression 'FacilityID' as part of an aggregate function."
What am I doing wrong?