我的一个函数:(供下面的过程调用)
function TFormReport.partquery6(add: string; prop: string): cardinal;
begin    //有二个查询条件add,prop;
  query1.sql.clear;
  query1.sql.add('select count(*) as countz ');
  query1.sql.add('from teacher');
  query1.sql.add('where left(xxdm,2)='''+add+''' and zwjb='''+prop+'''');
  query1.open;
  result:=query1.fieldbyname('countz').AsInteger;
end;
===========================
我的插入表数据的过程:
procedure TFormReport.insertbaobiao6;
var n1,n2,n3,n4,n:cardinal;
 i,j:integer;
 str1,str2:string;
 f:real;
begin
  table1.close;
  table1.tablename:='baobiao06';
  table1.open;
  table1.next;         //skip the first row
  query1.close;
  edit1.Enabled :=true;
  showmessage('begin');
  for i:=1 to 29 do   //1到29,但其中有不连续。
    begin
     if i=9 then continue;           //跳过不要的条件。
     if (11<i) and (i<21)  then
       continue;
     str1:=inttostr(i);
     if i<10 then
        str1:='0'+inttostr(i);
     //中学专业技术职务          ////调用函数开始统计。
     for j:=11 to 14 do
       begin
        str2:=inttostr(j);
        n:=partquery6(str1,str2);
        if j=11 then n1:=n;
        if j=12 then n2:=n;
        if j=13 then n3:=n;
        if j=14 then n4:=n;
       end;
      table1.edit;
      table1.fieldbyname('zxgj').AsInteger:=n1;
      table1.fieldbyname('zxyj').AsInteger:=n2;
      table1.fieldbyname('zxej').AsInteger:=n3;
      table1.fieldbyname('zxsj').AsInteger:=n4;
      table1.post;
     //小学专业技术职务
     for j:=21 to 24 do
       begin
        str2:=inttostr(j);
        n:=partquery6(str1,str2);
        if j=21 then n1:=n;
        if j=22 then n2:=n;
        if j=23 then n3:=n;
        if j=24 then n4:=n;
       end;
      table1.edit;
      table1.fieldbyname('xxgj').AsInteger:=n1;
      table1.fieldbyname('xxyj').AsInteger:=n2;
      table1.fieldbyname('xxej').AsInteger:=n3;
      table1.fieldbyname('xxsj').AsInteger:=n4;
      table1.post;
      //其他专业技术职务
      for j:=31 to 33 do
       begin
        str2:=inttostr(j);
        n:=partquery6(str1,str2);
        if j=31 then n1:=n;
        if j=32 then n2:=n;
        if j=33 then n3:=n;
       end;
      table1.edit;
      table1.fieldbyname('qtgj').AsInteger:=n1;
      table1.fieldbyname('qtzj').AsInteger:=n2;
      table1.fieldbyname('qtcj').AsInteger:=n3;
      table1.post;
      //双师专业技术职务
      for j:=41 to 44 do
       begin
        str2:=inttostr(j);
        n:=partquery6(str1,str2);
        if j=41 then n1:=n;
        if j=42 then n2:=n;
        if j=43 then n3:=n;
        if j=44 then n4:=n;
       end;
      table1.edit;
      table1.fieldbyname('ssagj').AsInteger:=n1;
      table1.fieldbyname('ssazj').AsInteger:=n2;
      table1.fieldbyname('ssbgj').AsInteger:=n3;
      table1.fieldbyname('ssbzj').AsInteger:=n4;
      table1.post;
     //未定级
     str2:='99';
     n:=partquery6(str1,str2);
     table1.edit;
     table1.fieldbyname('wdj').AsInteger:=n;
     table1.post;
     //合计数
    n:=0;
     for j:=3 to 18 do
        n:=n+table1.fields[j].AsInteger;
     table1.edit;
     table1.fieldbyname('hj').AsInteger:=n;
     table1.post;                     ///统计结束
     //所占比例
     n1:=table1.fieldbyname('wdj').AsInteger;
     f:=n1/n;
     f:=1-f;
     table1.edit;
     table1.fieldbyname('bl').AsString:=Format('%.2f', [f]);
     table1.post;
    //////
    showmessage(table1.fieldbyname('csxm').AsString+'的数据已生成,将汇总下一城市数据');
   end;//end of for i;end;//end of procedure;
//////////=
=======================
Access 数据库、50万条数据、大概100分钟。
========================
呜呜呜呜呜
还有就吗?
============

解决方案 »

  1.   

    实在是看不下去了,太烦了,不过你如此频繁的调用那句SQL语句是不合算的,因为两个进程间的通讯就要消耗大量的时间,所以要么让统计的工作在数据库中用存储过程做,要么在客户端(即Delphi中)完成。
      

  2.   

    实在是看不下去了,太烦了,不过你如此频繁的调用那句SQL语句是不合算的,因为两个进程间的通讯就要消耗大量的时间,所以要么让统计的工作在数据库中用存储过程做,要么在客户端(即Delphi中)完成。
      

  3.   

    实在是看不下去了,太烦了,不过你如此频繁的调用那句SQL语句是不合算的,因为两个进程间的通讯就要消耗大量的时间,所以要么让统计的工作在数据库中用存储过程做,要么在客户端(即Delphi中)完成。
      

  4.   

    好像只是对一个表的统计啊,你把Teacher 表和baobiao6的结构传上来让大家看看好不好?
      

  5.   

    baobiao6的结构从程序中就可以看出来:
    字段:
    csxm
    要填统计值的
    hj,,zxgj,zxyj,zxej,zxsj
    xxyj,xxej,xxsj
    qtgj,qtzj,qtcj
    ssagj,ssazj,ssbgj,ssbzj
    wdj
    bl
    =============
    sql中用Count(*) as countz;
    ==========================
    teacher表字段也较多,查询中只用到了二个字段的一部分。
    如:                       字段1                    字段2     
    query1.sql.add('where left(xxdm,2)='''+add+''' and zwjb='''+prop+'''');
    ======================================
    如何?