declare @t table(年龄 int)
insert into @t select 22
union all select 23
union all select 24
union all select 22
union all select 25select
年龄,
count(年龄) as 频数,
rtrim(cast((count(年龄)+0.0)/(select count(*) from @t) as float)*100)+'%' as 百分比
from
@t
group by
年龄
order by
年龄
insert into @t select 22
union all select 23
union all select 24
union all select 22
union all select 25select
年龄,
count(年龄) as 频数,
rtrim(cast((count(年龄)+0.0)/(select count(*) from @t) as float)*100)+'%' as 百分比
from
@t
group by
年龄
order by
年龄
insert #t
select 22
union all select 23
union all select 24
union all select 22
union all select 25
goselect id,count(*) 频数,cast(count(*) as decimal(8,2))/(select count(*) from #t) 百分比
from #t
group by id
insert into @t select 22
union all select 23
union all select 24
union all select 22
union all select 25select
年龄,
count(年龄) as 频数,
cast((count(年龄)+0.0)/(select count(*) from @t) as dec(10,1)) as 百分比
into #t
from
@t
group by
年龄
order by
年龄select
a.年龄,
a.频数,
(select sum(isnull(频数,0)) from #t where 年龄<=a.年龄) as 累计频数,
rtrim(百分比*100)+'%' as 百分比,
rtrim((select sum(isnull(百分比,0)*100) from #t where 年龄<=a.年龄))+'%' as 累计百分比
from #t adrop table #t--这样?
insert into taa select 22
union all select 23
union all select 24
union all select 22
union all select 25select 年龄,RTRIM(cast(cast(count(*)*100.0/(select count(*) from taa) as dec(6,2))as char(10)))+'%',
RTRIM(cast(cast((select count(*) from taa where 年龄<=a.年龄)*100.0/(select count(*) from taa) as dec(6,2))as char(10)))+'%'
from taa a group by 年龄
(select count(*) from taa where 年龄<=a.年龄)累计频数,
RTRIM(cast(cast(count(*)*100.0/(select count(*) from taa) as dec(6,2))as char(10)))+'%' 百分比,
RTRIM(cast(cast((select count(*) from taa where 年龄<=a.年龄)*100.0/(select count(*) from taa) as dec(6,2))as char(10)))+'%' 累计百分比
from taa a group by 年龄