多行同列数据合并

select
 字段1, [字段2]=stuff((select ';'+[字段2] from tb  where id=t.id for xml path('')), 1, 1, '') 
from
 tb t
group by
 字段1 

  重点是使用for xml path('')生成xml格式,使用''去掉尖括号;

 

参考:https://www.cnblogs.com/doubleliang/archive/2011/07/06/2098775.html

posted @ 2018-06-22 17:30  ruijian  阅读(167)  评论(0编辑  收藏  举报