开发者

how to add columns data in sql server?

in sql server 2008, i have two columns pr开发者_JAVA技巧oductu_code,quantity how to add quantity when product is same

      ______________________
      |productcode|quantity|
      ----------------------
      |FH5004     |  8     |
      |FH5016     |  4     |
      |FH5029     |  2     |
      |FH5004     |  6     |
      |FH5016     |  2     |
      |____________________|

  can you help me, thank you.


SELECT productcode, 
       sum(quantity) as total_quantity
FROM YourTable
GROUP BY productcode


SELECT SUM(Quantity) FROM table_name GROUP BY ProductCode 

Is that what you're after?


You can use this SQL:

SELECT productcode, SUM(quantity) as total_quantity
FROM Table t1
GROUP BY productcode
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜