Hello,
I need some help with the mySQL SORT statement for listing reviews by how helpful they were rated by users.
I have two columns in the review table: helpfulrate and totalrate. helpfulrate contains the number of people that rated the review helpful and totalrate contains the total number of people that rated the review. I use the two columns to get "XX out of XX people found this review helpful".
Right now I am using the following text for sorting the reviews by which is most helpful:
"... ORDER by IFNULL(helpfulrate/totalrate,0) DESC,totalrate DESC"
The above code orders by the highest percentage first (of people who rated the review helpful divided by the total number of people that rated the review), then orders by the total number of people that rated the review.
So 50 out of 50 people would be higher than 1 out of 1 or 2 out of 2.
The problem is, why should a review that is only 1 out of 1 be ranked higher than a review that is 250 out of 251. I know that it shouldn't.
Amazon.com has some way for sorting well, but I just can't figure out a good way to do it.
Can anyone help at all?
I don't expect a full out answer (although it would be nice 🙂). It would be great if someone could point me in the right direction.
Thanks for your time,
Andrew