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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.