Forum Moderators: coopster

Message Too Old, No Replies

ordering by avg()

         

PokeTech

1:15 am on Apr 6, 2009 (gmt 0)

10+ Year Member



Here's my table:

CREATE TABLE `ratings` (
`rid` int(255) NOT NULL auto_increment,
`uid` varchar(255) NOT NULL default '',
`sid` varchar(255) NOT NULL default '',
`rating` enum('1','2','3','4','5') NOT NULL default '1',
`date` varchar(255) NOT NULL default '',
PRIMARY KEY (`rid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=403 ;

I want to take and group all the sid's and group them together and then display them out based on the average of the rating.

Something like this:
SELECT * FROM ratings GROUP BY sid ORDER BY AVG(rating)

That doesn't work and I'm not quite sure how to make it work. If anyone can help it would be greatly appreciated!

d40sithui

3:38 pm on Apr 6, 2009 (gmt 0)

10+ Year Member



try this one::

SELECT sid, avg(rating) as average FROM ratings GROUP BY sid ORDER BY average;

PokeTech

4:17 pm on Apr 6, 2009 (gmt 0)

10+ Year Member



Thanks that worked!