用SQL查询占比?

占比前面的所有列是一个表,用SQL查询出所有表中原有的内容并计算出占比,占比是=每行中的haoshiH除以相同fbillno的haoshiH总和

sqlserver写法
创建表
create table test
(id int,
name varchar(1))
insert into test values (1,'a')
insert into test values (2,'a')
insert into test values (1,'a')
insert into test values (1,'a')
insert into test values (2,'a')
执行
select a.id,a.count1,(a.count1+0.0)/b.count2
from
(select id,count(*) count1 from test group by id) a,
(select count(*) count2 from test) b追问

貌似理解错了。你用我的数据源写一下呢

温馨提示:答案为网友推荐,仅供参考