试试:
select bh,sum(cb) as cb from
(select bh,isnull(sum(cb),0) as cb from tab group by bh
union all
select bh1 as bh,isnull(sum(cb1),0) as cb from tab group by bh1)t
group by bh
select bh,sum(cb) as cb from
(select bh,isnull(sum(cb),0) as cb from tab group by bh
union all
select bh1 as bh,isnull(sum(cb1),0) as cb from tab group by bh1)t
group by bh
(select bh,cb from tab
union all
select bh1 as bh,cb1 as cb from tab where bh1 is not null)t
group by bh
order by bh
[email protected]