需求:
将一列的多個值合并成一行并用逗号分割
效果
sql文法:
mysql寫法:
--預設的逗号分隔
select GROUP_CONCAT(A.title) as citys from tmpcity A;
--用空格分隔
select GROUP_CONCAT(A.title SEPARATOR ' ') as citys from tmpcity A;
select WM_CONCAT(A.title) as citys from tmpcity A
select stuff((select ','+A.title from tmpCity A FOR xml PATH('')), 1, 1, '') as citys