SQL Server 多行数据,将某一列拼接字符串

针对查询多行用Group By进行分组,想把某一列进行拼接组成字符串返回

最佳解决方案

示例:

select s.cloumn1,s.cloumn2,

stuff((

select ','+CAST(cloumn3 as varchar(20))

from Table2 where cloumn1=s.cloumn1and IsDeleted=0 group by cloumn3 for xml path('')),1,1,'')as cloumn4

from Table1 s

inner join Table1 o on o.SpecialistId=s.SpecialistId and o.IsDeleted=0

where s.SpecialistId=2

group by s.SpecialistId,s.TrueName 


RW_xuheng T0 被采纳率100%
2020-10-28 09:27
打赏 0 1
页面统计
1293 访问
0 帮助
0.00 打赏

hierror 2019 © hierror.com 京ICP备13026190号-1

通知消息
  • 暂无任何消息