select 备注1,d.com_name,sum( 应收) as '应收'--下面的条件已经筛选为未收费
from checkup c,[company] d
where c.备注1=d.com_id and 备注1<>'' and 收费状态='未收费'
group by 备注1,d.com_name
from checkup c,[company] d
where c.备注1=d.com_id and 备注1<>'' and 收费状态='未收费'
group by 备注1,d.com_name
[code=SQL]select a.备注1,com_name, 应收1,应收2,应收3,应收4,应收5,应收6,...,b.qtf from (
select 备注1,d.com_name,
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收1'
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收2'
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收3'
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收4'
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收5'
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收6'
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收7'
sum(case when 收费状态='未收费' then 应收 else 0 end) as '应收8'
.
.
.
from checkup c,[company] d
where c.备注1=d.com_id and 备注1<>'' and 收费状态='未收费' group by 备注1,d.com_name
) a
left outer join (select dbddm, sum(qtf) qtf from [server] where dbddm is not null group by dbddm) b
on a.备注1=b.dbddm[/code]