Surya sasidhar
Surya sasidhar

Reputation: 30303

how to add columns data in sql server?

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.

Upvotes: 0

Views: 306

Answers (3)

Saket
Saket

Reputation: 46127

You can use this SQL:

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

Upvotes: 1

AndrewC
AndrewC

Reputation: 6730

SELECT SUM(Quantity) FROM table_name GROUP BY ProductCode 

Is that what you're after?

Upvotes: 1

Martin Smith
Martin Smith

Reputation: 453028

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

Upvotes: 2

Related Questions