create table T(区域 char(1),类型 int)
insert into T select 'A',1
insert into T select 'B',2
insert into T select 'C',3
insert into T select 'A',4
insert into T select 'A',5
insert into T select 'B',1
insert into T select 'B',2
declare @s varchar(8000)
set @s=''
select @s=@s+',['+区域+']=convert(varchar(10),sum(case 区域 when '''+区域+''' then 1 else 0 end))+''条'''
from T group by 区域 order by 区域
exec('select CASE WHEN (GROUPING(类型) = 1)
THEN ''总计'' else convert(char(6),类型) END AS 类型'+@s+' from T group by 类型 WITH ROLLUP order by 类型')
drop table t
/*
类型 A B C
------ ------------ ------------ ------------
1 1条 1条 0条
2 0条 2条 0条
3 0条 0条 1条
4 1条 0条 0条
5 1条 0条 0条
总计 3条 3条 1条
*/