表1
   编号      得分      类别编号
   1         90.5        1
   1         88          1
   2         95          2
   2         90          3 
   2         87.5        2
  ...................表2 
  类别编号   占总分值百分比
    1           80
    2           10
    3           10要求表1 按编号分组统计合计实际得分数。要考虑表2中所占百分比。

解决方案 »

  1.   

    --try toselect a.编号,实得分=sum(a.得分*b.占总分值百分比/100.0)
     from 表1 as a inner join 表2 as b on a.类别编号=b.类别编号
    group by a.编号
      

  2.   

    select a.编号,sum(a.得分*b.占总分值百分比/100.0) 实际得分数 
    from 表1 a,表2 b 
    where a.类别编号=b.类别编号
    group by a.编号
      

  3.   

    select a.编号,实得分=sum(a.得分*b.占总分值百分比/100.0)
     from 表1 as a inner join 表2 as b on a.类别编号=b.类别编号
    group by a.编号
      

  4.   

    用个子查询
    select 得分*b.占总分值百分比/100.0,a.类型编号
    from
    (select 得分=sum(得分),类别编号 from 表1 
    group by 类型编号)a
    inner join 表2 b on a.类型编号=b.类型编号
      

  5.   

    create table 表1
    (
     编号 int,
     得分 decimal(4,1),
     类别编号 int
    )
    create table 表2
    (
     类别编号 int,
     占总分值百分比 int
    )insert into 表1 select 1,90.5,1
    insert into 表1 select 1,88,1
    union all select 2,95,2
    union all select 2,90,3
    union all select 2,87.5,2 
    insert into 表2 select 1,80
    union all select 2,10
    union all select 3,10
    select 实际分数=t3.总得分*t1.占总分值百分比/100 from 表2 t1,(select 类别编号,总得分=sum(得分) from 表1 group by 类别编号)t3 where t1.类别编号 = t3.类别编号
    drop table 表1,表2
    /*
    实际分数                                     
    ---------------------------------------- 
    142.800000
    18.250000
    9.000000(所影响的行数为 3 行)
    */
      

  6.   

    select b.类别编号,c.score*b.占总分值百分比/100 as 总分值 from b,(select 类别编号,sum(得分) as score from a  group by 类别编号) c
     where c.类别编号=b.类别编号
    表1 a
    表2 b