SQL将表中某一类型的一列拼接成一行
SELECT
TypeName
,(SELECT ','+ UserName FROM [ContainerMembers] t WHERE TypeName= aa.TypeName FOR XML PATH('')) AS Users
FROM [ContainerMembers] aa
GROUP BY [TypeName]
SELECT
TypeName
,(SELECT ','+ UserName FROM [ContainerMembers] t WHERE TypeName= aa.TypeName FOR XML PATH('')) AS Users
FROM [ContainerMembers] aa
GROUP BY [TypeName]