worked a treat, will take me a while to work out whats happening with that one but thank you so much for your help.
You are a legend!
User Profile
Collapse
-
if i do:
i get single datesCode:SELECT MAX(`Date`) strength FROM InspectionsNZ WHERE HiveID IN(SELECT Hives.ID FROM Hives LEFT JOIN Contacts ON Contacts.ContactID = Hives.ContactID WHERE RunGroup = '$run' GROUP BY Hives.ID)
but when i just run the sub query i do get all the hiveID's
...Code:SELECT Hives.ID strength FROM Hives LEFT JOIN Contacts ON Contacts.ContactID = Hives.ContactID WHERE RunGroup = '$run' GROUP BY Hi
Leave a comment:
-
makes sense...
would that be best done using another sub query or is there another more efficient way way to join 3 tables ?Leave a comment:
-
I am getting only one date for each group where i should be getting all MAX inspection Dates for each hive in the group.
Group Hives Customers Avg Hive StrengthCode:SELECT MAX(`Date`) strength FROM InspectionsNZ LEFT JOIN Contacts ON InspectionsNZ.CustomerID = Contacts.ContactID WHERE RunGroup = '$run'
Kumeu 30 13 19-12-11
Manukau 20 10 20-12-11
Mt Albert 18 9 19-01-12...Leave a comment:
-
nope still get the 0 0 with 'Date' and `Date` good thinking though...
Thanks for your help...Leave a comment:
-
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Date]) FROM InspectionsNZ LEFT JOIN Contacts ON InspectionsNZ.C ustomerID = Con' at line 9Leave a comment:
-
wrong,
should be 0 0 8 9 5 4 1 0 8 6 0 0 7 2
what is getting is 0 0Leave a comment:
-
Ok i think i know what the problem might be.... the sub query is looking for the MAX date so it will average only the HiveStrengths of inspections done on the latest date for each group.
Instead it should be averaging the hive strength of the latest inspection for each hive in the group... if that makes any sense?Leave a comment:
-
Ok, have taken out the AVG (i get what you meant now) and for the example i gave it is averaging 0 0 instead of
0 2012/1/12
0 2012/1/12
8 2012/1/12
9 2012/1/12
5 2012/1/12
4 2012/1/12
1 2012/1/12
0 2012/1/12
8 2012/1/12
6 2012/1/12
0 2012/1/12
0 2012/1/12
7 2012/1/12
2 2012/1/12Leave a comment:
-
you mean take out the MAX from the sub query?
Also, would it matter if "hiveStreng th' was 0 ?Leave a comment:
-
These are the Hive Strengths of the latest inspections from one group:
Hive Strenght | Date
0 2012/1/12
0 2012/1/12
8 2012/1/12
9 2012/1/12
5 2012/1/12
4 2012/1/12
1 2012/1/12
0 2012/1/12...Leave a comment:
-
Average on MAX by Group
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...
No activity results to display
Show More
Leave a comment: