开发者

how to add columns data in sql server?

开发者 https://www.devze.com 2023-04-06 06:26 出处:网络
in sql server 2008, i have two columns pr开发者_JAVA技巧oductu_code,quantity how to add quantity when product is same

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

精彩评论

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