1. 程式人生 > >SQL語句 合併列值 將一列的多個值合併成一行

SQL語句 合併列值 將一列的多個值合併成一行

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

MySQL寫法:

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