group_concat in mysql, oracle, mss

需求:

  tb_region
province city   province city
四川 成都

====》

四川 成都,绵阳,德阳
浙江 杭州 浙江 杭州,宁波
江苏 南京 江苏 南京
四川 绵阳    
四川 德阳    
浙江 宁波      

 

mysql:

select 
province,
group_concat(distinct city order by city separator ',') as city
from
tb_region
group by province

Oracle:

select 
province,
listagg(city,',') within group (order by city) as city
from
tb_region
group by province

Sql Server:

select
r2.province,
(select
    r1.city + ','
 from tb_region r1
    where r1.province=r2.province for XML path('')) as concat_city
from tb_region r2
group by r2.province

 

你可能感兴趣的:(group_concat)