更新时间:2022-11-27 15:33:41
您要使用 FOR XML PATH
构造:
select
ID,
stuff((select ', ' + Value
from YourTable t2 where t1.ID = t2.ID
for xml path('')),
1,2,'') [Values]
from YourTable t1
group by ID
STUFF
函数是为了摆脱前导','
。
The STUFF
function is to get rid of the leading ', '
.
您还可以看到另一个此处的示例:
You can also see another examples here: