select
id,
F1,
F2,
rtrim(cast((select count(F2) from 表)*100.0/(select sum(F2) from 表) as numeric(5,2)))+'%'
from
表
id,
F1,
F2,
rtrim(cast((select count(F2) from 表)*100.0/(select sum(F2) from 表) as numeric(5,2)))+'%'
from
表
id,
F1,
F2,
cast(cast((select count(F2) from #1 where F2=a.F2)*100.0/(select count(F2) from #1) as numeric(5,2)) as varchar)+'%'
from
#1 a
这样的结果都成了一样了
select
1 , 'A' , 'A'
union all select
2 , 'B' , 'BB'
union all select
3 , 'C' , 'CC'
union all select
4 , 'D' , 'DD'
union all select
5 , 'E' , 'EE'
union all select
6 , 'F' , 'FF'
union all select
7 , 'G' , 'GG'
union all select
8 , 'H' , 'FF'
union all select
9 , 'I' , 'GG'
select
id,
F1,
F2,
cast(cast((select count(F2) from #1 where F2=a.F2)*100.0/(select count(F2) from #1) as numeric(5,2)) as varchar)+'%'
from
#1 a结果如下所示:
1 A A 11.11%
2 B BB 11.11%
3 C CC 11.11%
4 D DD 11.11%
5 E EE 11.11%
6 F FF 22.22%
7 G GG 22.22%
8 H FF 22.22%
9 I GG 22.22%