SQL Server sql 合并字符串

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版本以及更高版本才能用奥!

猜你喜欢

转载自tankywang.iteye.com/blog/1539819