回复 20楼 csyx
我也得研究一下,谢谢!
虽然代码多了些,但耗时减少到两秒左右,以空间换时间还是值得的
程序代码:Close Databases
Use cj In 0
Select xh, dsdm, xqdm, xxdm, kh ;
,yw, Cast(0 as I) ywlkx, Cast(0 as I) ywbsx, Cast(0 as I) ywbxx ;
,sx, Cast(0 as I) sxlkx, Cast(0 as I) sxbsx, Cast(0 as I) sxbxx ;
,yy, Cast(0 as I) yylkx, Cast(0 as I) yybsx, Cast(0 as I) yybxx ;
from cj into cursor result Readwrite
m.ss = Seconds()
For m.ii = 1 to ALines(aTemp, 'yw,sx,yy', ',')
m.科目 = aTemp[ii]
? '统计 ' + m.科目 + ' 总排名 ... '
Select &科目 成绩, 0 分组, Count(*) 人数, Cast(0 as I) 排名 ;
from result group by 成绩 order by 成绩 desc into cursor temp Readwrite
SetRank('temp')
Update t set t.&科目.lkx = s.排名 from result t inner join temp s on t.&科目 = s.成绩
? '统计 ' + m.科目 + ' 市排名 ... '
Select &科目 成绩, dsdm 分组, Count(*) 人数, Cast(0 as I) 排名 ;
from result group by 分组, 成绩 order by 分组, 成绩 desc into cursor temp Readwrite
SetRank('temp')
Update t set t.&科目.bsx = s.排名 from result t inner join temp s on t.&科目 = s.成绩 and t.dsdm = s.分组
? '统计 ' + m.科目 + ' 乡排名 ... '
Select &科目 成绩, xqdm 分组, Count(*) 人数, Cast(0 as I) 排名 ;
from result group by 分组, 成绩 order by 分组, 成绩 desc into cursor temp Readwrite
SetRank('temp')
Update t set t.&科目.bxx = s.排名 from result t inner join temp s on t.&科目 = s.成绩 and t.xqdm = s.分组
EndFor
Use in temp
? '总耗时', Seconds() - m.ss
Select result
Locate
Browse
Function SetRank(als)
Local n分组, n排名
Select (m.als)
Locate
m.n分组 = -1
Scan all
If 分组 != m.n分组
m.n分组 = 分组
m.n排名 = 1
EndIf
Replace next 1 排名 with m.n排名
m.n排名 = m.n排名 + 人数
EndScan
EndFunc
把我定义/使用的字段/变量,拼音改成了汉字,这样容易看明白
[此贴子已经被作者于2023-8-14 09:18编辑过]










