[英]Select sum of column and display top 3 MAX Sum with limit LIMIT
I have bellow snippet table 我有波纹管摘要表
Here i have to sum vote top 3 values. 在这里,我必须对投票的前3个值求和。
Suppose product_id
3030
have sum of vote
column is 8.1
and the 3671
sum
is 5.2
假设product_id
3030
的vote
总和栏为8.1
而3671
sum
为5.2
here i have to get top 3 product_id which have max sum like bellow example output. 在这里,我必须获得前3个product_id,它们具有以下示例示例输出所示的最大和。
here max sum product_id
id 3030
have sum
8.1
and second is 3671
have sum
5.2
这里最大总和product_id
id 3030
有sum
8.1
,第二个是3671
有sum
5.2
I Have tried bellow query but it not showing top 3 product_id
Max Top 3 of sum vote. 我尝试了波纹管查询,但未显示总和最高的前3个product_id
。
$query = mysql_query("SELECT sum(vote) AS 'meta_sum',product_id FROM rating GROUP BY product_id ASC LIMIT 3") OR DIE(mysql_error())
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. 上面的查询将返回SUM(vote)
值最大的前3
产品。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.