如何求总分;
    现有一数据库如下:
    学号  姓名   语文  数学   英语  ...  总分  名次
    001   kk    70    80     68   ...
    002   ll    80    90     70   ...
    003   oo    90    98     80   ...
    .......
课程、人数不定
求每位学生的总分???现有部分代码如下;(只能求当前记录的总分,加循环不行。特向高人求救,在线等)  ''计算有几个字段
  for Each fd In Data1.Database.Tabledefs.(tableindex).Fieds
       fieldcount=fieldcount + 1
  next  ''从第三个字段开始加到倒数第三个结束
  for i=2 to fieldcount-3
    sun=data1.recordset.fields(i)+sun
  next i
  
  ''更新数据
  data1.recordset.edit
  data1.recordset.fields(fieldcount-2).value=sun
  data1.recordset.update

解决方案 »

  1.   

    if not(data1.recordset.bof or data1.recordset.eof ) then
      data1.recordset.movefirst
    end if
    while not (data1.recordset.bof or data1.recordset.eof) 
     你的部分代码
     data1.recordset.movenext
    wend
      

  2.   

    conn.open ........
    conn.excute "update 表 set 总分=语文+数学+....."就可以了
      

  3.   

    ret as adodb.recordset
    select * from biao 
    if not ret.eof then
    ret.movefirst
    do while not ret.eof
    ret.fields(总分)=ret.fields(语文)+ret.fields(数学)+ret.fields(英文)...
    ret.movenext
    loop
    end if
      

  4.   

    回复人: jackshj(闪电骑士) ( ) 信誉:95  2004-04-26 19:01:00  得分:0 
     
     
      课程个数,顺序不定!!
      
     
    for Each fd In Data1.Database.Tabledefs.(tableindex).Fieds
           fieldcount=fieldcount + 1
      next
    你可以用这个fd.name提出来啊
    不过感觉,还是设置哪几个字段比较好
      

  5.   

    首先我先说明一下:
    你的数据库的结构太差了,使用起来太不灵活了,如果要解决问题最好是把数据库结构改动一下最好了编号(自动)   学号    姓名    科目    分数
    1            1       张三    语文    100
    2            1       张三    数学    98
    3            1       张三    物理    98
    4            2       小洪    语文    92.......
    然后利用交叉表的统计得到你想要的信息有一個表 StudentMark它的結構和數據如下
    (編號),  (學號)   , (課程編號),(分數),(考試編號)
    ID   ,     StdID  ,   CourseID,  Mark,  Type
    int  ,     char(6),   char(5) ,  float, int1,         00533     ,語文,      50,     1
    2,         00533     ,數學,      70,     1
    3,         00533     ,英語,      60,     14,         00534     ,語文,      70,     1
    5,         00534     ,數學,      53,     1
    6,         00534     ,英語,      58,     17,         00534     ,語文,      90,     2
    8,         00534     ,數學,      63,     2
    9,         00534     ,英語,      88,     2
    10,        00534     ,法學,      100,    2 
    編號     學號    語文, 數學,  英語,    法學,    平均分, 考試編號
    1,      00533,    50,   70   ,  60,                 60,        1
    2,      00534     70,   53,  ,  58,                 60.3,      1  
    3,      00534     90,   63,     88,      100        87.7       2
    declare @s varchar(8000)
    set @s=''
    select @s=@s+',['+CourseID+']=sum(case CourseID when '''+CourseID+''' then Mark else 0 end)'
    from StudentMark
    group by CourseID
    exec('select 編號=identity(int,1,1),學號=StdID'+@s+',平均分=avg(Mark),考試編號=Type
    into #t
    from StudentMark
    group by StdID,Type
    select * from #t
    ')