原创

Sql groupby分组和stuff

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/sinat_34170721/article/details/52400138

begin

with aa as

(

select distinct a.MaintenanceOrderNo,b.BusinessType from PartsLibrary a

left join MaintenanceOrPartsOrder b

on a.MainNo=b.MaintenanceOrPartsNo

where a.PartsID in('06274564-391b-4b66-9b0d-3d0901d346b7',

'0770edef-d85f-41e4-8b9c-37dc883f4156','0e66ad2f-3200-445d-b456-0824a03f6057','15c0e163-30ca-42b5-81b0-b484c583be7c',

'427f27cf-4f0a-4078-a46a-d4a1501197f4','4d0aaf17-333e-42fd-b775-82259ca9d23c')

)

select aa.BusinessType,SettlementNo=stuff((select ','+t.MaintenanceOrderNo fromaa t 

     where t.BusinessType=aa.BusinessType 

     for xml path('')), 1, 1, '')  from aa

     group by aa.BusinessType

end

文章最后发布于: 2016-09-01 15:26:37
展开阅读全文
0 个人打赏