0

in sql server 2008, i have two columns productu_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.

3 Answers 3

2
SELECT productcode, 
       sum(quantity) as total_quantity
FROM YourTable
GROUP BY productcode
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT SUM(Quantity) FROM table_name GROUP BY ProductCode 

Is that what you're after?

Comments

1

You can use this SQL:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.