1.关联多表后 根据某个字段作为分组条件,其他合并到新列中,效果如下图
-------->
代码:
select KUserID, KOrderID=stuff((select ','+Convert(varchar(10),KOrderID) from VOrder2 t where KUserID=tb.KUserID for xml path('')), 1, 1, '') from VOrder2 tb group by KUserID
2.单个表直接转换单列合并
select stuff((select ','+Convert(varchar(10),PID) from AA where State=1 for xml path('')), 1, 1, '') as PID