SQL语句:合并列值(将一列的多个值合并成一行)

需求:

将一列的多个值合并成一行并用逗号分割

效果
在这里插入图片描述

sql语法:

mysql写法:

 --默认的逗号分隔
select GROUP_CONCAT(A.title) as citys from tmpcity A;     

 --用空格分隔
select GROUP_CONCAT(A.title SEPARATOR  ' ') as citys from tmpcity A; 

oralce写法:

select WM_CONCAT(A.title) as citys from tmpcity A

sql server写法:

select stuff((select ','+A.title from tmpCity A FOR xml PATH('')), 1, 1, '') as citys

 

posted on 2020-03-11 00:02  静以修身俭以养德  阅读(4628)  评论(0编辑  收藏  举报

导航