I have a query which is performing 2 calculations. The first one is a 2-part calculation called AcresDiv5. In the first part, it sums all the crop acreage on a particular site, and in the second part this sum is divided by 5. The second calculation, called SumDevices, is the sum of all noisemaking devices on each site.
The goal is to find those farms at or exceeding the allowable noisemaking devices (1 device allowed per 5 acres of crop).
I want to add a "Where" or "Having" clause to find those records where SumDevices >= AcresDiv5.
Here is my SQL so far, looks very bulky but works fine, just can't get this final step. Any ideas??
Thanks in advance for any help.
Eadie
SELECT [Address LUT].ID, [Address LUT].Address, People.Name, People.Phone, Sum(Varieties.Acres) AS SumOfAcres, (Sum([Acres])/5) AS AcresDiv5, [Bird Control].[Triple Shots], [Bird Control].Cannons, [Bird Control].[AV Alarms], [Bird Control].[Orchard Pistols], (Nz([Bird Control].[Orchard Pistols],0))+(Nz([Bird Control].[Cannons],0))+(Nz([Bird Control].[Triple Shots],0))+(Nz([Bird Control].[AV Alarms],0)) AS SumDevices
FROM [Address LUT], Varieties, [Bird Control], People
WHERE ((([Address LUT].ID)=[Varieties].[ID]) AND (([Bird Control].ID)=[Address LUT].[ID]) AND ((People.GrowerID)=[Address LUT].[GrowerID]))
GROUP BY [Address LUT].ID, [Address LUT].Address, People.Name, People.Phone, [Bird Control].[Triple Shots], [Bird Control].Cannons, [Bird Control].[AV Alarms], [Bird Control].[Orchard Pistols], [Address LUT].GrowerID;
The goal is to find those farms at or exceeding the allowable noisemaking devices (1 device allowed per 5 acres of crop).
I want to add a "Where" or "Having" clause to find those records where SumDevices >= AcresDiv5.
Here is my SQL so far, looks very bulky but works fine, just can't get this final step. Any ideas??
Thanks in advance for any help.
Eadie
SELECT [Address LUT].ID, [Address LUT].Address, People.Name, People.Phone, Sum(Varieties.Acres) AS SumOfAcres, (Sum([Acres])/5) AS AcresDiv5, [Bird Control].[Triple Shots], [Bird Control].Cannons, [Bird Control].[AV Alarms], [Bird Control].[Orchard Pistols], (Nz([Bird Control].[Orchard Pistols],0))+(Nz([Bird Control].[Cannons],0))+(Nz([Bird Control].[Triple Shots],0))+(Nz([Bird Control].[AV Alarms],0)) AS SumDevices
FROM [Address LUT], Varieties, [Bird Control], People
WHERE ((([Address LUT].ID)=[Varieties].[ID]) AND (([Bird Control].ID)=[Address LUT].[ID]) AND ((People.GrowerID)=[Address LUT].[GrowerID]))
GROUP BY [Address LUT].ID, [Address LUT].Address, People.Name, People.Phone, [Bird Control].[Triple Shots], [Bird Control].Cannons, [Bird Control].[AV Alarms], [Bird Control].[Orchard Pistols], [Address LUT].GrowerID;