简体   繁体   English

Mysql查询查找具有相同列值的字段总和

[英]Mysql query to find sum of fields with same column value

I have a table like this 我有一张这样的桌子

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 我希望获得具有相同发明ID的订单数量的总和

That is the want the result like this 那就是想要这样的结果

   |  invent_id         |   order
   | 95948214           | 240
   | 46018572           | 100
   | 36025764           | 130

how can we write the mysql query 我们怎样才能编写mysql查询

Make use of Aggregate function SUM and grouped them according to invent_id . 使用聚合函数SUM并根据invent_id它们进行invent_id

SELECT invent_id, SUM(`order`) `Order`
FROM tableName
GROUP BY invent_ID

GROUP BY clause GROUP BY子句

SQLFiddle Demo SQLFiddle演示

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

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