User Profile

Collapse

Profile Sidebar

Collapse
JulianMcCurdy
JulianMcCurdy
Last Activity: Feb 4 '12, 02:03 AM
Joined: Feb 2 '12
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • JulianMcCurdy
    replied to Average on MAX by Group
    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!
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    if i do:
    Code:
    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)
    i get single dates

    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
    ...
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    makes sense...

    would that be best done using another sub query or is there another more efficient way way to join 3 tables ?
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    I am getting only one date for each group where i should be getting all MAX inspection Dates for each hive in the group.



    Code:
    SELECT MAX(`Date`) strength FROM InspectionsNZ LEFT JOIN Contacts ON InspectionsNZ.CustomerID = Contacts.ContactID WHERE RunGroup = '$run'
    Group Hives Customers Avg Hive Strength
    Kumeu 30 13 19-12-11
    Manukau 20 10 20-12-11
    Mt Albert 18 9 19-01-12...
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    nope still get the 0 0 with 'Date' and `Date` good thinking though...

    Thanks for your help...
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    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 9
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    wrong,

    should be 0 0 8 9 5 4 1 0 8 6 0 0 7 2

    what is getting is 0 0
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    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?
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    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/12
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    you mean take out the MAX from the sub query?

    Also, would it matter if "hiveStreng th' was 0 ?
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    replied to Average on MAX by Group
    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...
    See more | Go to post

    Leave a comment:


  • JulianMcCurdy
    started a topic Average on MAX by Group

    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...
    See more | Go to post
No activity results to display
Show More
Working...