CLOSE DATABASES ALL
CREATE CURSOR zjfb (序号 c(12),姓名 c(8),班级数 n(5,0),班级名 c(100),总分 n(5,0),平均 n(7,2))
USE 第一学期期中积分 IN 0 ALIAS jfb
SELECT jfb
* 初始化
LOCAL azd[FCOUNT()-2],czd
czd=""
FOR i=3 TO FCOUNT()
azd[i-2]=FIELD(i)
ENDFOR
DIMENSION azd[ALEN(azd)/4,4]
*LIST MEMORY LIKE azd
FOR i=1 TO ALEN(azd,1)
czd=czd+IIF(EMPTY(czd),"",",")+azd[i,2]+","+azd[i,3]
ENDFOR
BLANK ALL FIELDS &czd
* 排名次、积分计算
FOR i=1 TO ALEN(azd,1)
INDEX on 类型+STR(100000-&azd[i,1]) TO cj
nmc=1
clb=""
SCAN
nmc=IIF(类型==clb,nmc+1,1)
REPLACE ((azd[i,2])) WITH nmc
clb=类型
nmc=EVALUATE(azd[i,2])
ENDSCAN
REPLACE ALL (azd[i,3]) WITH 21-EVALUATE(azd[i,2])
ENDFOR
SET ORDER TO
BROWSE
* 统计班级数、平均分
FOR i=1 TO ALEN(azd,1)
INDEX on &azd[i,4] TO xm
xm=""
nxh=1
SCAN
IF &azd[i,4]==xm
REPLACE 班级数 WITH 班级数+1,班级名 WITH 班级名-","-jfb.类型-jfb.bj,总分 WITH 总分+EVALUATE("jfb."+azd[i,1]),平均 WITH 总分/班级数 IN zjfb
ELSE
INSERT INTO zjfb VALUES (azd[i,4]+TRANSFORM(nxh),EVALUATE("jfb."+azd[i,4]),1,jfb.类型-jfb.bj,EVALUATE("jfb."+azd[i,1]),EVALUATE("jfb."+azd[i,1]))
nxh=nxh+1
ENDIF
xm=&azd[i,4]
ENDSCAN
ENDFOR
SELECT zjfb
BROWSE