22,209
社区成员
发帖
与我相关
我的任务
分享
with t(ID,CourOrder,BookID) as(
select 1,'3',418 union all
select 2,'6',418 union all
select 3,'5',418 union all
select 4,'1',520 union all
select 5,'2',520 union all
select 6,'3',520)
SELECT STUFF((SELECT ','+[CourOrder] FROM t WHERE BookID=t1.BookID FOR XML PATH('')), 1, 1, '') as CourOrderSTR,BookID
FROM t t1
GROUP BY BookID