select id, stuff((select ','+name from (select distinct id,name from tb) b where b.id=a.id for xml path('')),1,1,'') from (select distinct id,name from tb) a group by id
注意要SQL2005版本以及更高版本才能用奥!
select id, stuff((select ','+name from (select distinct id,name from tb) b where b.id=a.id for xml path('')),1,1,'') from (select distinct id,name from tb) a group by id
注意要SQL2005版本以及更高版本才能用奥!