I have a 5 star rating system at my side and i want to view top 3 best rated, I am using the below sql query:
SELECT Ranking, Total_value FROM <Table> ORDER BY Rating DESC LIMIT 3;
but it don't show the top 3, it shows the 3 with the highest number, if 10 people have voted for one thing, and 20 people have voted for another thing, the one with 20 votes have the highest number, but not necessary have the highest rating, so how do i divide the number of votes with the total ranking?? so it shows the 3 with the best ranking
Hope someone can help me? and understand my question :)
You can divide Total_value
with Total_votes
:
SELECT
Ranking,
Total_votes,
Total_value,
(Total_value / Total_votes) as `Average`
FROM
Votes
ORDER BY
(Total_value / Total_votes) DESC
LIMIT 10
You have to created a column in database called average.And update the average each time people rates.Then use query
SELECT Ranking, Total_value FROM ORDER BY average_value DESC LIMIT 3;