If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Need help with sorting by MAX average!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-03-10, 14:55
bmarshall.0511 bmarshall.0511 is offline
Registered User
 
Join Date: Mar 2010
Location: Dallas, TX
Posts: 1
Question 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.
Reply With Quote
  #2 (permalink)  
Old 03-03-10, 15:54
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
remove the MAX function and try the query again
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Tags
avg, max, order by, sort

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On