Hi,
I have a database with 3 tables, Contacts, Hives, and Inspections with Contact ID as the key.
Contacts
ContactID | RunGroup
Hives
HiveID | ContactID
InspectionsNZ
ContactID | HiveID | Hive Strength | Date
Each contact has multiple hives and each hive has multiple inspections.
I am trying to average the hive strength from the latest of all inspections belonging to contacts in an individual group
So far i have
At the moment i am not getiing accurat averages, im not sure what it is averaging but its not giving the correct results.
Thanks for your help. Loving this forum.
Julian
I have a database with 3 tables, Contacts, Hives, and Inspections with Contact ID as the key.
Contacts
ContactID | RunGroup
Hives
HiveID | ContactID
InspectionsNZ
ContactID | HiveID | Hive Strength | Date
Each contact has multiple hives and each hive has multiple inspections.
I am trying to average the hive strength from the latest of all inspections belonging to contacts in an individual group
So far i have
Code:
SELECT ROUND(AVG(HiveStrength), 1) strength FROM InspectionsNZ LEFT JOIN Contacts ON Contacts.ContactID = InspectionsNZ.CustomerID WHERE Contacts.RunGroup = '$run' AND InspectionsNZ.Date IN (SELECT MAX(Date) FROM InspectionsNZ LEFT JOIN Contacts ON InspectionsNZ.CustomerID = Contacts.ContactID WHERE RunGroup = '$run' AND Contacts.Status = 'Active' AND Type = 'Rental') AND Contacts.Status = 'Active' AND Type = 'Rental'
Thanks for your help. Loving this forum.
Julian
Comment