57,064
社区成员
发帖
与我相关
我的任务
分享select comid
,sum(case when Flag='A' then cnt else 0 end) AS Acnt
,sum(case when Flag='B' then cnt else 0 end) AS Bcnt
,sum(case when Flag='C' then cnt else 0 end) AS Ccnt
,coms.names
,users.names
from
(select *,'A' as Flag from A
union all
select *,'B' as Flag from B
union all
select *,'C' as Flag from C
) as T
left join coms on coms.id = T.comid
left join users on users.id = T.comsid
group by comid,coms.names,users.names
select comid
,sum(case when Flag='A' then cnt else 0 end) AS Acnt
,sum(case when Flag='B' then cnt else 0 end) AS Bcnt
,sum(case when Flag='C' then cnt else 0 end) AS Ccnt
from
(select *,'A' as Flag from A
union all
select *,'B' as Flag from B
union all
select *,'C' as Flag from C
) as T
group by comid