一、有如下两个表:
table1                              table2
bh   xm   zh       je               bh   xm   zh       je
1    aa   123       50.00            1   aa   256      60.00
2    bb   565       100.00           2   cd   558      120.00
3    cc   2322      20.00            5   gg   596      50.00
要将两个表进行合并,合并后要求如下:
bh   xm   zh       je              
1    aa   123       110.00           
2    bb   565       220.00 
3    cc   2322      20.00            
5    gg   596       50.00
即按编号(bh)合并,编号不同的全都加到新表中,
编号相同的金额(je)相加,其他字段的内容沿用table1的内容二、
  delete from table_name where confitipns
  为何执行后老出错
请各位大侠指教,谢谢!!!!!

解决方案 »

  1.   

    这里是两个问题,sixgj什么写的不对,我不明白,请指教
      

  2.   

    1 table1.first;
      while not table1.eof do
      begin
        确定table2中与table1.bh相同记录之je并相加;
        插入table3;
        table1.next;
      end;2 问题写的不清楚
      

  3.   

    这样不行,两表的循序并不完全一样;
    我用query.sql可以执行相同编号的金额相加,但不相同的无法追加;
     select * from table1,table2 where table1.bh=table2.bh 
     order by table1.bh and table2.bh 
     然后执行金额相加;接着追加编号不同的记录;
    .........
      select * from table1,table2 where table1.bh<>table2.bh 
     order by table1.bh and table2.bh 
    然而条件where table1.bh<>table2.bh 不能进行精确查找
    我测试的表只有两条记录不同,但结果有20多条,大部分都重复
    条件where table1.bh<>table2.bh  语句有问题吗?请指教!
     
      

  4.   

    select bh=isnull(a.bh,b.bh) ,xm=isnull(a.xm,b.xm), je=isnull(a.je,0)+isnull(b.je,0) from table1 as a full join table2 as b on a.bh=b.bh