1

the table is like this

Product_Group value a 100 a 50 b 50 b 50 b 100 c 200 

and I need to create a new column and at the same time take out the redundancy in Product_Group, so the result should be

Product_group Sum a 150 b 200 c 200 

Cheers!

2
  • do you actually need to remove the records permanently and update permanently or just show the results in a select? also what version of sql are you using? (sql-server, oracle, mysql?) Commented Jun 24, 2015 at 13:57
  • 1
    what is your database? SQL Server or MYSql or else? Commented Jun 24, 2015 at 14:00

2 Answers 2

2

You can use Group BY Clause. However, this is not a good idea to use reseverd keyword SUM as a column name, but if you want to wrap in bracekts.

SELECT Product_group, SUM(Value) as [SUM] FROM tablename GROUP BY Product_group 
Sign up to request clarification or add additional context in comments.

Comments

0

Use the following Query in MySQL

 SELECT Product_group, SUM(Value) "SUM" FROM tablename GROUP BY Product_group 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.