MySQL查询以查找具有相同列值的字段总和 [英] Mysql query to find sum of fields with same column value
本文介绍了MySQL查询以查找具有相同列值的字段总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张这样的桌子
id | invent_id | order
1 | 95948214 | 70
2 | 46018572 | 30
3 | 46018572 | 20
4 | 46018572 | 50
5 | 36025764 | 60
6 | 36025764 | 70
7 | 95948214 | 80
8 | 95948214 | 90
我想获得具有相同发明编号的订单数量之和
I want get the sum of order qty with same invent id
就是想要这样的结果
| invent_id | order
| 95948214 | 240
| 46018572 | 100
| 36025764 | 130
我们如何编写mysql查询
how can we write the mysql query
推荐答案
使用聚合函数SUM
并根据invent_id
将它们分组.
Make use of Aggregate function SUM
and grouped them according to invent_id
.
SELECT invent_id, SUM(`order`) `Order`
FROM tableName
GROUP BY invent_ID
GROUP BY clause
这篇关于MySQL查询以查找具有相同列值的字段总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文