开发者

Merge similar rows and sum their values?

开发者 https://www.devze.com 2023-04-10 17:07 出处:网络
This is my table: URL| Art | Design example1.com1 example1.com1 example1.com1 example1.com1 example2.com1 example2.com1

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
0

精彩评论

暂无评论...
验证码 换一张
取 消