var i,j,k:integer;
begin    aq_2.SQL.Clear;
    aq_2.SQL.Add('select mc,tjbh from gl_custom where tjbh like ''011%'' order by tjbh');
    aq_2.Active:=true;{列客户名}
    aq_1.SQL.Clear;
    aq_1.SQL.Add('select tjbh,hh,sum(sl) from fhdzk where tjbh like ''011%'' and cdbz=0 and kdrq>='''+ed_qs.Text+''''+' and '+'kdrq<='''+ed_js.Text+''' group by tjbh,hh' );
    aq_1.Active:=true;{列销售汇总}
    sgrid.ColCount:=9;
    i:=1;
    j:=1;
    while not aq_2.Eof do
    begin
        sgrid.Cells[0,i]:=aq_2.Fields[0].AsString;
        sgrid.Cells[1,i]:=inttostr(0);
        {aq2}
        while not aq_1.Eof do
        begin
            if aq_1.Fields[0].AsString=aq_2.Fields[1].AsString then
                begin
                    sgrid.Cells[1,i]:=inttostr(strtoint(sgrid.Cells[1,i])+strtoint(Aq_1.Fields[2].AsString));
                    aq_1.Next;
                end
            else
                begin
                    aq_1.Next;
                end;
        end;
        aq_2.Next;
        i:=i+1;    end;{写单位}
end;
为什么我把aq_2放在{aq2}的位置上,查询就可以得到结果,但速度奇慢
放在aq_1下面,就只循环一次,然后遇上    while not aq_2.Eof do就退出了,怎样解决?

解决方案 »

  1.   

    我用Adoquery select 一组数据,扫描后,指针移到尾端。怎样让它重返最前?
      

  2.   

    我知道你的意思了:
    在网格上列出客户以及销售总额,用了两个while 循环进行统计,你可以这样用一个while循环来实现:
     aq_1.first;
     while not aq_2.Eof do
        begin
            sgrid.Cells[0,i]:=aq_2.Fields[0].AsString;
            sgrid.Cells[1,i]:=inttostr(0);
            if aq_1.Fields[0].AsString=aq_2.Fields[1].AsString then
            begin
              sgrid.Cells[1,i]:=inttostr(strtoint(sgrid.Cells[1,i])+strtoint  (Aq_1.Fields[2].AsString));
              aq_1.Next;
            end
            else if (aq_1.Bof<>eof) and (aq_1.Fields[0].AsString<aq_2.Fields[1].AsString) then
              aq_1.Next;
            aq_2.Next;
            i:=i+1;
        end;{写单位}