34,576
社区成员
发帖
与我相关
我的任务
分享
with tb(a,b,c,d)as(
select 1, 1, '内部阅办', 'cp' union all
select 1, 2, '分配项目组', 'xm' union all
select 1, 1, '内部阅办', 'zj' union all
select 2, 1, '会签', 'xm' union all
select 2, 1, '会签', 'cp' union all
select 3, 1, '独立节点', 'user1'
)
select distinct a,b,stuff((select ','+d from tb where a.a=a and a.b=b for xml path('')) ,1,1,'')d
from tb a where not exists (select 1 from tb where a=a.a and a.b<b)
/*
运行结果
a b d
1 2 xm
2 1 xm,cp
3 1 user1
*/