以下sql语句把多行数据中的某一列用逗号分隔合成为一列
SELECT t.field,COUNT(*),STUFF(
(SELECT ' , ' + t1.field2
FROM tablename as t1
WHERE t1.field = t.field
FOR xml path('')
),1,1,''
) FROM tablename t group by t.field Having COUNT(*)>1 order by COUNT(*)