简体   繁体   中英

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

That is the want the result like this

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

how can we write the mysql query

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

SQLFiddle Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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