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
精彩评论