简体   繁体   English

MySql Query对行进行求和并获得最大值

[英]MySql Query to sum the rows and get the max value

I have a table product with sample data as below 我有一个包含样本数据的表产品,如下所示

product  1   2  2   3   1          
Quantity 10 15  20  10  5 

I need to findout which product has highest quantity after summing up all the available quantity for all the products 在总结所有产品的所有可用数量后,我需要找出哪个产品的数量最多

Example: Here answer would be 15+20 = 35 is greatest so product 2 has more quantity 示例:这里的答案是15 + 20 = 35最大,因此产品2的数量更多

please help with query 请帮忙查询

select product, sum(quantity) as sum_quantity
from products
group by product
order by sum_quantity desc
limit 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM