SQLServer分组后按字段拼接

SELECT 字段1, 
         [随便来个名字就行] = stuff((
                 SELECT ',' + [字段2] 
                   FROM aa t 
                  WHERE t.字段1 = aa.字段1 
                    FOR xml path('')) , 1 , 1 , '') 
    FROM aa 
GROUP BY 字段1

  

posted @ 2019-07-19 16:17  大侠的哥哥是菜鸟  阅读(6364)  评论(0编辑  收藏  举报