lisovaccaro
lisovaccaro

Reputation: 33956

Merge similar rows and sum their values?

This is my table:

URL           | Art | Design 
example1.com     1             
example1.com     1             
example1.com     1             
example1.com            1         
example2.com            1
example2.com            1

I want to merge columns with same URL and sum the values of Art and Design in the process, to get something like:

URL           | Art | Design
example1.com     3      1
example2.com            2

How is this done?

Upvotes: 3

Views: 2897

Answers (5)

Kangkan
Kangkan

Reputation: 15571

Have you tried anything till now?

It is as simple as:

select url, SUM(art) as Art, SUM(design) as Design from [MyTable] group by url

Upvotes: 0

coolguy
coolguy

Reputation: 7954

select url,SUM(art),SUM(design) from  tab1 group by url

Where tab1 is your table name

Upvotes: 1

Aziz Shaikh
Aziz Shaikh

Reputation: 16524

Try this:

SELECT URL, COUNT(Art), COUNT(Design)
FROM myTable
GROUP BY URL

Upvotes: 0

rahularyansharma
rahularyansharma

Reputation: 10755

select URL,sum(art),sum(design) From MYTABLE group by URl

Upvotes: 1

Mark Byers
Mark Byers

Reputation: 838216

Use GROUP BY and SUM:

SELECT URL, SUM(Art) as Art, SUM(Design) AS Design
FROM yourtable
GROUP BY URL

Upvotes: 4

Related Questions