我用ado+access2000做的下程序,access2000有个cy的表,里面有5000记录
我用下面这个查询好像效率不高,要耗时近2秒钟才能完成
begin
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select count(*) from cy where 语文>=:d and left(xsbh,5)="c0301"');
ADOQUERY3.Parameters[0].Value:=90;
adoquery3.Active:=true;
edit1.Text:=adoquery3.Fields[0].Value;
end;
能不能将这个查询优化一下,因为在我这个程序里有16个循环,每个循环里面有14个上面类似的查询,也就是说,完成它要近4分钟!
有没有办法快点呀?
我用下面这个查询好像效率不高,要耗时近2秒钟才能完成
begin
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select count(*) from cy where 语文>=:d and left(xsbh,5)="c0301"');
ADOQUERY3.Parameters[0].Value:=90;
adoquery3.Active:=true;
edit1.Text:=adoquery3.Fields[0].Value;
end;
能不能将这个查询优化一下,因为在我这个程序里有16个循环,每个循环里面有14个上面类似的查询,也就是说,完成它要近4分钟!
有没有办法快点呀?
解决方案 »
- 做一个东西,模拟执行某个软件。
- IdTCPServer和IdTCPClient客户端服务器端都发record数据包的例子谁有啊,谢谢
- 数据库不能实时刷新的问题
- 关于Treeview某节点的值被修改后,数据库某字段值更新成新的值的问题,进来看看,up有分
- 对于高手,这是一个简单的问题。可是对我,却能让我失去学习的信心!
- 如何把一个文件保存到数据库中?????(很复杂的一个问题)
- 使用过ehlib控件的朋友请进
- 问个最基本的问题?大家不要骂我!
- 求搭救~~国庆假期不知道又没人~关于DBGRID的用法的~急
- 哪里有好、的图标下载呀谢谢,我也程序要用!
- 关于多线程图形问题?(我用多线程做图形动作处理,多线程无法即时处理完我的图形上窗界操作!)
- 急急~~关于ADOTABLE打开数据表的问题..
progressbar1.Max:=combobox1.Items.Count-1;
bhtemp:=bh;
for i:=1 to combobox1.Items.Count-1 do//一般combobox1.Items.Count为16到20左右
begin
progressbar1.Position:=i;
if i<10 then
bh:=bh+'0'+inttostr(i)
else
bh:=bh+inttostr(i);//求学校编号
adoquery3.close;
adoquery3.sql.clear;
ADOQUERY3.SQL.ADD('select xxmc from xxdm where xxbm=:i');
ADOQUERY3.Parameters[0].Value:=inttostr(i);
adoquery3.Open;
mc:=adoquery3.Fields[0].Value;//求学校名称
adoquery3.close;
adoquery3.sql.clear;
ADOQUERY3.SQL.ADD('select count(*) from cy where left(xsbh,5)="'+bh+'"');
adoquery3.Open;
sbs:=adoquery3.Fields[0].Value;//求学生上报数
adoquery3.close;
adoquery3.sql.clear;
ADOQUERY3.SQL.ADD('select count(*) from cy where left(xsbh,5)="'+bh+'" and '+combobox3.Text+'>=0');
adoquery3.Open;
sks:=adoquery3.Fields[0].Value;//求学生的实考数
ckl:=sks/sbs*100;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select avg( '+combobox3.Text+') from cy where left(xsbh,5)="'+bh+'"');
adoquery3.Active:=true;
pjf:=adoquery3.Fields[0].Value;//求平均分(这里耗时较长1.5秒)
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select mf from kcsz where nj="初一" and kc=:kc');
ADOQUERY3.Parameters[0].Value:=combobox3.Text;
adoquery3.Active:=true;
mf:=adoquery3.Fields[0].Value;//求满分
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select count(*) from cy where '+combobox3.Text+'>=:fs and left(xsbh,5)="'+bh+'"');
ADOQUERY3.Parameters[0].Value:=mf*0.6;
adoquery3.Active:=true;
jgl:=adoquery3.Fields[0].Value/sks*100;求及格率(这里也要耗时1.5秒)
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select sum('+combobox3.Text+'*'+combobox3.Text+') from cy where '+combobox3.Text+'>-1 and left(xsbh,5)="'+bh+'"');
adoquery3.Active:=true;
x1:=adoquery3.Fields[0].Value;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select sum('+combobox3.Text+')*sum('+combobox3.Text+')from cy where '+combobox3.Text+'>-1 and left(xsbh,5)="'+bh+'"');
adoquery3.Active:=true;
x2:=adoquery3.Fields[0].Value;
bzc:=sqrt((x1-x2/sks)/(sks-1));//这里求标准差(这里也要耗时1.5秒)
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select a,b,c,d from ddqz where nj="初一" and kc=:kc');
ADOQUERY3.Parameters[0].Value:=combobox3.Text;
adoquery3.Active:=true;
a:=adoquery3.Fields[0].Value;
b:=adoquery3.Fields[1].Value;
c:=adoquery3.Fields[2].Value;
d:=adoquery3.Fields[3].Value;
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select count(*) from cy where '+combobox3.Text+'>=:a and left(xsbh,5)="'+bh+'"');
ADOQUERY3.Parameters[0].Value:=a;
adoquery3.Active:=true;
a:= adoquery3.Fields[0].Value;
adl:=a/sks*100;//求A等率(这里也要耗时1.5秒)
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select count(*) from cy where '+combobox3.Text+'>=:b and left(xsbh,5)="'+bh+'"');
ADOQUERY3.Parameters[0].Value:=b;
adoquery3.Active:=true;
b:=adoquery3.Fields[0].Value;
bdl:=(b-a)/sks*100;//求B等率(这里也要耗时1.5秒)
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select count(*) from cy where '+combobox3.Text+'>=:c and left(xsbh,5)="'+bh+'"');
ADOQUERY3.Parameters[0].Value:=c;
adoquery3.Active:=true;
c:=adoquery3.Fields[0].Value;
cdl:=(c-b)/sks*100;//求C等率(这里也要耗时1.5秒)
adoquery3.Close;
adoquery3.SQL.Clear;
adoquery3.SQL.Add('select count(*) from cy where '+combobox3.Text+'>=:d and left(xsbh,5)="'+bh+'"');
ADOQUERY3.Parameters[0].Value:=d;
adoquery3.Active:=true;
d:=adoquery3.Fields[0].Value;
ddl:=(d-c)/sks*100;//求D等率(这里也要耗时1.5秒)
edl:=100-adl-bdl-cdl-ddl;//求E等率
jlz:=(6*adl+4*bdl+3*cdl+ddl-edl)/100;//求均量值
adoquery3.close;
adoquery3.sql.clear;
ADOQUERY3.SQL.ADD('INSERT INTO pjb values ("'+bh+'","'+mc+'",'+inttostr(sbs)+','+inttostr(sks)+','+floattostr(ckl)+','+floattostr(pjf)+','+floattostr(jgl)+','+floattostr(bzc)+','+floattostr(adl)+','+floattostr(bdl)+','+floattostr(cdl)+','+floattostr(ddl)+','+floattostr(edl)+','+floattostr(jlz)+')');
adoquery3.ExecSQL;//将各个值写入数据表pjb中
bh:=bhtemp;
end;
showmessage('统计完成!!');
你可以将查询放在一个预处理过程中,将查询的结果放在数组中.在循环过程中从数组中取值.
另外我觉得你需要学习一下SQL命令了,好象很多SQL可以联在一起,
2.不要频繁进行Close、Open操作。对可在一次查询中得到的值,尽量在一次操作中全部返回。