如何实现比例计算

flowerguest 2005-07-10 01:20:48

name count

.
.
.
.

declare @allcount int
set @allcount = (select sum(count) from test
select name,count/@allcount as percent from test

...全文
115 点赞 收藏 5

5 条回复

brother2605 2005-07-11

select a.name,(sum(count)/b.count)as percent from
test a cross join (select sum(count)as count from test) b

group by a.name
order by a.name

wangdehao 2005-07-10
select name,(sum(count)+0.0)/(select sum(count) from test)as [percent] from test group by name

filebat 2005-07-10
--你还可以用连接来做
--测试数据与'依帆'相同
select t1.*, percents=1.0*counts/sums
from (select name, counts=sum(count) from test group by name)t1
, (select sums=sum(count)from test)t2

geniusqing 2005-07-10
create table test(name varchar(6),count int)
insert into test
select '张三', 10
union all select '李四', 4

select name,sum(count),(sum(count)+0.0)/(select sum(count) from test) from test group by name

geniusqing 2005-07-10
select name,sum(count),(sum(count)+0.0)/(select sum(count) from test) from test group by name

2.7w+

MS-SQL Server 应用实例

2005-07-10 01:20