先生成临时表再解决你的汇总吧。
select 学生编号, 学生代号, 模块, max(模块成绩)  into #temp
  from  table
 group by 学生编号, 学生代号, 模块

解决方案 »

  1.   

    添加一个标识id,计算之后再删除
    alter table 表 add id int identity(1,1)
    select * into #t from (
    select *
    from 表
    where id in (select max(id) from 表 group by 学生编号, 学生代号,模块) )tselect sum(模块成绩) as aa from #t where 学生编号=1 group by 学生代号drop table #t
      

  2.   

    估计你的记录是有时间顺序的吧。group by 的时候取max(date)应该是。
      

  3.   

    select identity(int,1,1) as ID,学生编号,模块,模块成绩 
    into #t
    from 表
    select 
        sum(a.模块成绩) as aa
    from
        #t a,
        (select max(ID) as ID from #t group by 学生编号,学生代号,模块) b
    where
        a.ID = b.ID and 学生编号=1
    group by
        a.学生代号drop table #t
      

  4.   

    建议表里建一个autoid字段(自增1)select sum(模块成绩) as aa from 表 where 学生编号=1 and autoid in
    (select max(autoid) autoid from 表 group by 学生代号,模块)
    group by 学生代号
      

  5.   

    alter table 表 add id int identity(1,1)select sum(模块成绩)
    from 表
    where id in (select max(id) from 表 group by 学生编号, 学生代号,模块) 
    group by 学生代号alter table 表 drop id
      

  6.   

    我的想法是能不能在查询的时候使用DISTINCT 学生代号,模块   把重复的去掉,再求 模块成绩  的和
      

  7.   


    create table t
    (
    bm varchar(1),
    dh varchar(1),
    md varchar(1),
    cj decimal(28,2))
    insert into t values(1,2,5,10)
    insert into t values(1,2,6,10)
    insert into t values(1,2,6,8)
    select sum(cj) as aa from (
    select bm,dh,md,min(cj) as cj from tgroup by bm,dh,md )  xwhere x.bm=1 group by dhdrop table t
      

  8.   

    select top 1 sum(模块成绩) as aa from 表 where 学生编号=1 group by 学生代号 order by 模块成绩 asc