declare @t table(总分 numeric(5,3),人数 int,题号 int,分值 numeric(5,3),年 int,月 int)
insert into @t select 0.001 ,1,1,0.001 ,2006,2
insert into @t select 1.000 ,1,1,1.000 ,2006,2
insert into @t select 4.000 ,2,1,2.000 ,2006,2
insert into @t select 3.000 ,1,1,3.000 ,2006,2
insert into @t select 4.000 ,1,1,4.000 ,2006,2
insert into @t select 10.000,2,1,5.000 ,2006,2
insert into @t select 12.000,2,1,6.000 ,2006,2
insert into @t select 7.000 ,1,1,7.000 ,2006,2
insert into @t select 9.000 ,1,1,9.000 ,2006,2
insert into @t select 10.000,1,1,10.000,2006,2
insert into @t select 10.000,1,2,10.000,2006,2
insert into @t select 8.000 ,1,3,8.000 ,2006,2
insert into @t select 5.000 ,1,5,5.000 ,2006,2
insert into @t select 4.000 ,1,8,4.000 ,2006,2
insert into @t select 1.000 ,1,8,1.000 ,2006,2select 题号,avg(人数*分值) 平均得分 from @t group by 题号/*
题号        平均得分
----------- ---------
1           6.000100
2           10.000000
3           8.000000
5           5.000000
8           2.500000
*/

解决方案 »

  1.   

    select 题号, sum(总分)/ (select sum(人数) from aa  where 题号=b.题号 and score!
    =0.001)/10  as 得分率 from aa  b group by 题号
      

  2.   

    select 题号, sum(case when 分值=0.001 then 0 else 分值*人数 end )/sum(case when 分值=0.001 then 0 else 人数 end )
    from @t group by 题号
      

  3.   

    谢谢各位!libin_ftsafe(子陌红尘) 在这里人数已汇总时,结果不对。
     lsqkeke(可可) 和duoluohuifeng(堕落回风)方法经果都对!