Jump to content

ORDER BY AVG and COUNT


iceblox

Recommended Posts

Hi All,

 

I have a table of reviews and im trying to return the top 4 rated products by doing the below;

 

SELECT AVG(rating) as average_rating, COUNT(id) as number_reviews FROM ratings GROUP BY id ORDER BY average_rating DESC, number_reviews DESC 

 

The problem I have is that the average rating is not ordered correctly it seems to be giving priority to the number_reviews as this is ordered correctly.

 

Ive tried adding

WHERE number_reviews > 3 

but this doesnt seem to work.

 

Does any one have any suggestions on how best to return the data I need?

 

Many Thanks,

 

Link to comment
https://forums.phpfreaks.com/topic/247788-order-by-avg-and-count/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.