select mid,stuff((select distinct ','+uid from t1 where a.mid=mid for xml path('')),1,1,'') AS items from t1 a group by mid结果mid items 1 a,b,c,d2 a,b,c 3 a,b,c