22,207
社区成员
发帖
与我相关
我的任务
分享
create table ym
(col1 int, col2 int, col3 varchar(3))
insert into ym
select 1, 1, 'A' union all
select 1, 1, 'B' union all
select 1, 2, 'C' union all
select 1, 3, 'D' union all
select 1, 3, 'E'
select a.col1,a.col2,
stuff((select ','+col3 from ym b
where b.col1=a.col1 and b.col2=a.col2
for xml path('')),1,1,'') 'col3'
from ym a
group by a.col1,a.col2
你参考一下,自己改改吧