计算的问题DELPHI6+ADO+ACCESS2000有主从AA,BB两个表
表AA字段如下:编号       姓名
001        张三
002        李四
003        王五
004        赵大
..................表BB字段如下:(表AA和表BB通过编号建立主从关系,月份不会重复)
编号    月份      上月结转额     本月收入     本月支出    本月余额
001     2003-1                      80            70 
001     2003-2                      50
001     2003-3                                    30
001     2003-4                      120           60
001     2003-5                      100          100 
001     2003-6                                    80  
......
002    .......
002    .......
......
003
.....
请问,如何通过计算过程得出表BB的如下结果?编号    月份      上月结转额     本月收入     本月支出    本月余额
001     2003-1        0              80           70         10
001     2003-2       10              50                      60
001     2003-3       60                           30         90
001     2003-4       90              120          60        150
001     2003-5      150              100          100       150
001     2003-6      150                           70         80  
......
002    .......
002    .......
......
003
.....我的想法是用ADOTABLE1控件连接表AA:
While not adotable1.eof do
begin
  adoquery1.close;
  adoquery1.sql.text:='select * from bb where 编号='''+adotable1.filedname('编号').asstring+'''';(adoquery1为满足adotable1当前记录的表BB的所有值)
  adoquery1.open;
  while not adoQuery1.Eof do 
  begin 
    //?????????,此处计算代码如何写才好?
     adoQuery1.Next ; 
   end; 
end; 
  adotable1.next;
end; 
那位大侠有好的解决办法,如能告之在小,感激不尽:)。谢谢您的参与!

解决方案 »

  1.   

    不能,不过可以用视图来实现,建立一个视图,做复杂查询从aa和bb中查询出最后的结果
      

  2.   

    While not adotable1.eof do
    begin
      adoquery1.close;
      adoquery1.sql.clear; 
      adoquery1.sql.text:='select * from bb where 编号='''+adotable1.filedname('编号').asstring+'''';(adoquery1为满足adotable1当前记录的表BB的所有值)
      adoquery1.open;
      while not adoQuery1.Eof do 
      begin
        adoquery1.fields[2].asinterger:=adoquery1.fields[3].asinterger-adoquery1.fields[4].asinterger;
    adoquery1.fields[5].asinterger:=adoquery1.fields[2].asinterger; 
        //?????????,此处计算代码如何写才好?
         adoQuery1.Next ; 
       end; 
    end; 
      adotable1.next;
    end;