下面代码能否再优化,提高运行速度?
求列数据第1、2大的值:
1、在每100行数据中求
1列中第1、2大的值;
2、其差值在
1、2范围内时,在另表对应行标注
3、只要有1列符合条件,不再求另外的列,转入下一列(字段)重复上面。
主要在第3步处能否修改
程序代码:
*****求列第1、2大值
Set Talk Off
Set Safe Off
use bb in 0
use pmax in 0
FOR i=1 TO RECCOUNT()-99
SELECT * FROM bb WHERE BETWEEN(jnh,i,i+99) INTO TABLE lsb &&&每次选100条记录确定第1、2大值
SELECT lsb
kk=2
*****填充每列空白行序号值
FOR lnj = kk TO FCOUNT()
n1 = 0
SELECT * FROM lsb WHERE Not Empty(EVALUATE(FIELD(lnj))) INTO Cursor ls
IF RECCOUNT()>0
use
SELECT lsb
SCAN
c1 = EVALUATE(FIELD(lnj))
IF !EMPTY(c1)
n1 = 0
ELSE
n1 = n1 + 1
REPLACE (FIELD(lnj)) WITH TRANSFORM(n1)
ENDIF
ENDSCAN
endif
ENDFOR
*****保留填充序号最后的值(即空白行最大值)
USE fc\lsb IN 0 ALIAS t1 AGAIN
USE fc\lsb IN 0 ALIAS t2 AGAIN
SELECT t1
SET RELATION TO RECNO()+1 INTO "t2"
SELECT t1
FOR lnj = kk TO FCOUNT()
*n1 = 0
SELECT * FROM t1 WHERE Not Empty(EVALUATE(FIELD(lnj))) INTO Cursor ls
IF RECCOUNT()>0
use
SELECT t1
SCAN
c1 = EVALUATE('t1.'+FIELD(lnj))
c2 = EVALUATE('t2.'+FIELD(lnj))
REPLACE ('t1.'+FIELD(lnj)) with IIF(VAL(c2)>0 AND VAL(c1)>0 ,"",c1)
ENDSCAN
endif
ENDFOR
SET RELATION TO
SELECT t1
USE
SELECT t2
USE
SELECT lsb
****以上两段代码是列出空白行的数据,为下一代码求空白行数据的最大、次最大标数值。
***求列第1、2大值(主要代码段)
FOR lnj = kk TO FCOUNT("lsb")
Go BOTTOM
kjn=jnh &&确定在pmax标注时对应行
k1=VAL(EVALUATE(FIELD(lnj,"lsb"))) &&列最后行的值
Calculate Max(VAL(EVALUATE(FIELD(lnj,"lsb")))) To k2 &&列最大值(第1大值)
COUNT FOR !empty(EVALUATE(FIELD(lnj,"lsb"))) TO krow &&非空行数
IF k1=k2 AND k1>0 AND krow>20 AND k1<7 &&求第2大值,与最大值比较
cmd = [SELECT ]+FIELD(lnj,"lsb")+[ mk FROM lsb WHERE ISDIGIT(]+FIELD(lnj,"lsb")+[) ORDER BY ]+FIELD(lnj,"lsb")+[ DESC into cursor tmp]
EXECSCRIPT(cmd)
GO 2 IN "tmp"
k3 = VAL(tmp.mk) &&第2大值
IF INLIST(k2-k3,1,2) &&在pmax对应行标注
SELECT pmax
GO kjn
REPLACE mmax WITH 'MMAX'
SELECT lsb
EXIT &&结束本轮字段循环
ENDIF
SELECT lsb
ENDIF
ENDFOR
ENDFOR
sele pmax
brow
[此贴子已经被作者于2021-9-18 19:07编辑过]