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 li开发者_如何学JAVAke:
URL | Art | Design
example1.com 3 1
example2.com 2
How is this done?
Use GROUP BY and SUM:
SELECT URL, SUM(Art) as Art, SUM(Design) AS Design
FROM yourtable
GROUP BY URL
select URL,sum(art),sum(design) From MYTABLE group by URl
select url,SUM(art),SUM(design) from tab1 group by url
Where tab1 is your table name
Try this:
SELECT URL, COUNT(Art), COUNT(Design)
FROM myTable
GROUP BY URL
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
精彩评论