修改后的帖子:
有朋友问我,回个贴子:
假定第一列为学号,接下来的是科目和总分,代码如下(较多的使用了宏变换,效率会有影响,但代码是通用的):
IF !USED("cj")
USE cj IN 0
ENDIF
SELECT cj
FOR nFieldNumber=4 TO FCOUNT("cj")
cField=FIELD(nFieldNumber,"cj")
SELECT bj,&cField ,coun(*) as co FROM cj GROUP BY &cField ORDER BY &cField DESC INTO TABLE temp
pm=cField+"排名"
ALTER TABLE temp ADD COLUMN &pm n(4)
a=0
b=1
FOR i=1 TO RECCOUNT()
REPLACE &pm WITH a+b
a=co
b=&pm
SKIP
ENDFOR
IF nFieldNumber=4
SELECT cj.bj,cj.zkzh,cj.xm,cj.&cField,temp.&pm FROM cj,temp WHERE cj.&cField =temp.&cField ORDER BY cj.&cField DESC into CURSOR temp20
ELSE
SELECT cj.bj,cj.zkzh,cj.xm,cj.&cField,temp.&pm FROM cj,temp WHERE cj.&cField =temp.&cField ORDER BY cj.&cField DESC into CURSOR temp21
IF (nFieldNumber/2)<>INT(nFieldNumber/2)
SELECT temp20.*,temp21.&cField,temp21.&pm from temp20,temp21 WHERE ALLTRIM(temp20.zkzh)==ALLTRIM(temp21.zkzh) ORDER BY temp20.bj INTO CURSOR temp22
ELSE
SELECT temp22.*,temp21.&cField,temp21.&pm from temp22,temp21 WHERE ALLTRIM(temp22.zkzh)==ALLTRIM(temp21.zkzh) ORDER BY temp22.bj INTO CURSOR temp20
ENDIF
ENDIF
ENDFOR
IF ((FCOUNT("cj"))/2)<>int((FCOUNT("cj"))/2)
SELECT temp22
ELSE
SELECT temp20
ENDIF
COPY TO 排名表
CLOSE ALL
[[it] 本帖最后由 ibmlang_002 于 2008-9-19 14:18 编辑 [/it]]
有朋友问我,回个贴子:
假定第一列为学号,接下来的是科目和总分,代码如下(较多的使用了宏变换,效率会有影响,但代码是通用的):
IF !USED("cj")
USE cj IN 0
ENDIF
SELECT cj
FOR nFieldNumber=4 TO FCOUNT("cj")
cField=FIELD(nFieldNumber,"cj")
SELECT bj,&cField ,coun(*) as co FROM cj GROUP BY &cField ORDER BY &cField DESC INTO TABLE temp
pm=cField+"排名"
ALTER TABLE temp ADD COLUMN &pm n(4)
a=0
b=1
FOR i=1 TO RECCOUNT()
REPLACE &pm WITH a+b
a=co
b=&pm
SKIP
ENDFOR
IF nFieldNumber=4
SELECT cj.bj,cj.zkzh,cj.xm,cj.&cField,temp.&pm FROM cj,temp WHERE cj.&cField =temp.&cField ORDER BY cj.&cField DESC into CURSOR temp20
ELSE
SELECT cj.bj,cj.zkzh,cj.xm,cj.&cField,temp.&pm FROM cj,temp WHERE cj.&cField =temp.&cField ORDER BY cj.&cField DESC into CURSOR temp21
IF (nFieldNumber/2)<>INT(nFieldNumber/2)
SELECT temp20.*,temp21.&cField,temp21.&pm from temp20,temp21 WHERE ALLTRIM(temp20.zkzh)==ALLTRIM(temp21.zkzh) ORDER BY temp20.bj INTO CURSOR temp22
ELSE
SELECT temp22.*,temp21.&cField,temp21.&pm from temp22,temp21 WHERE ALLTRIM(temp22.zkzh)==ALLTRIM(temp21.zkzh) ORDER BY temp22.bj INTO CURSOR temp20
ENDIF
ENDIF
ENDFOR
IF ((FCOUNT("cj"))/2)<>int((FCOUNT("cj"))/2)
SELECT temp22
ELSE
SELECT temp20
ENDIF
COPY TO 排名表
CLOSE ALL
[[it] 本帖最后由 ibmlang_002 于 2008-9-19 14:18 编辑 [/it]]
VFP