I need to select records where sum of field dbo.EquipmentlaborEvent.Hours is greater than a set value.SELECT dbo.Region.CompanyRegionID as divison, dbo.Job.CompanyJobId as job, dbo.Batch.ReportDate as jobdate, dbo.Equipment.CompanyEquipmentID as equipmentID, dbo.Equipment.Name as equipmentname, sum(dbo.EquipmentLaborEvent.Hours) as hours FROM dbo.Region inner join dbo.Batch on dbo.Batch.RegionGuid = dbo.Region.RegionGuid inner join dbo.Event on dbo.Event.BatchGuid = dbo.Batch.BatchGuid inner join dbo.Job on dbo.Job.JobGuid = dbo.Event.JobGuid join dbo.Equipment on dbo.Equipment.JobGuid = dbo.Job.JobGuid join dbo.EquipmentLaborEvent on dbo.EquipmentLaborEvent.Eventguid = dbo.Event.EventGuidWHERE dbo.Region.CompanyRegionID = '00032' and sum(dbo.EquipmentlaborEvent.Hours) <= 50GROUP BY dbo.Region.CompanyRegionID, dbo.Job.CompanyJobID, dbo.Equipment.CompanyEquipmentID, dbo.Equipment.Name, dbo.Batch.ReportDateGO
Getting error:An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.