Mysql query to find sum of fields with same column value

时间:2022-10-21 23:45:53

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查询

1 个解决方案

#1


14  

Make use of Aggregate function SUM and grouped them according to invent_id.

使用聚合函数SUM并根据invent_id对它们进行分组。

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

GROUP BY clause

GROUP BY子句

SQLFiddle Demo

#1


14  

Make use of Aggregate function SUM and grouped them according to invent_id.

使用聚合函数SUM并根据invent_id对它们进行分组。

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

GROUP BY clause

GROUP BY子句

SQLFiddle Demo