Reputation: 2088
I have bellow snippet table
Here i have to sum vote top 3 values.
Suppose product_id
3030
have sum of vote
column is 8.1
and the 3671
sum
is 5.2
here i have to get top 3 product_id which have max sum like bellow example output.
here max sum product_id
id 3030
have sum
8.1
and second is 3671
have sum
5.2
I Have tried bellow query but it not showing top 3 product_id
Max Top 3 of sum vote.
$query = mysql_query("SELECT sum(vote) AS 'meta_sum',product_id FROM rating GROUP BY product_id ASC LIMIT 3") OR DIE(mysql_error())
Upvotes: 0
Views: 81
Reputation: 72165
Try this:
SELECT SUM(vote) AS 'meta_sum', product_id
FROM rating
GROUP BY product_id
ORDER BY 'meta_sum' DESC LIMIT 3
The above query will return the top 3
products having the greatest SUM(vote)
values.
Upvotes: 3