Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2010
    Location
    Dallas, TX
    Posts
    1

    Question Unanswered: Need help with sorting by MAX average!

    Alright so I'm sure this is probably something really stupid I haven't thought about yet but what I'm trying to due is sort rows by the MAX AVG. Basically I've got a table of records that relate to photos. These photos are rated by visitors and given a value of 1-5. The table columns in question look like this:

    photo_id,rating
    1,4
    1,3
    1,1
    2,3
    2,4

    So I thought something like this would work:

    Code:
    SELECT photo_id FROM table GROUP BY photo_id ORDER BY MAX(AVG(rating)) DESC
    Any help would be greatly appreciated.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    remove the MAX function and try the query again
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •