34,590
社区成员
发帖
与我相关
我的任务
分享
select a.cid,部门=max(case a.pid when 'A' then a.pname end), 负责人=max(case b.pid when 'B' then b.pname end)
from tb a ,tb b
where a.cid=b.cid
group by a.cid
结果:
1 财务部 小李
2 财务部 小陈
select
cid,
[部门]=max(case pid when 'A' then PNAME else '' end),
[负责人]=max(case pid when 'B' then PNAME else '' end)
from T2
group by cid
select cid,
max(case pid when a then pname end)as 部门,
max(case pid when b then panem end)as 负责人
from T2
group by cid
order by cid