SQL Server 将一列多行数据合并为一行

时间:2021-06-10 15:05:30

SELECT  DISTINCT [列名]

      ,STUFF(

                        (

                              SELECT ','+[列名]

                              FROM [表名]

                              WHERE [根据哪一列合并的列名]= A.列名

                              FOR XML PATH('')

                        )

                        ,1,1,''

                  )AS 合并的别名

  FROM [表名] AS 表的别名(A)