22,209
社区成员
发帖
与我相关
我的任务
分享
if object_id('tb') >0
drop table tb
create table tb
(
a int identity,
b varchar(2),
c int
)
go
insert into tb(b,c)
select 'a',2
union all
select 'b',6
union all
select 'c',1
union all
select 'b',3
union all
select 'a',5
select b, left(round( sum(c) * 1.00/(select sum(c) from tb) ,2),4)
from tb
group by b
a 0.41
b 0.53
c 0.06
--修改
select
类型,
ltrim(cast(sum(数量)*100.0/(sleect sum(数量) from tb) as dec(18,2)))+'%'
from
tb
group by
类型
select
类型,
ltrim(cast(count(1)*100.0/(sleect count(1) from tb) as dec(18,2)))+'%'
from
tb
group by
类型