create table tb1(id int identity(1,1),id_acount char(4),id_acountid char(2),sum_money money)
insert into tb1 select '0001','00',10
union all select '0002','00',60
union all select '0003','00',80
union all select '0004','00',60
union all select '0005','00',80
union all select '0006','00',100表tb2:create table tb2(id int identity(1,1),id_acount char(4),id_acountid char(2),sum_money money)
insert into tb2 select '0001','00',1000
union all select '0003','00',600
union all select '0005','00',800
create table tb3(id int identity(1,1),id_acount char(4),id_acountid char(2),sum_money money)
insert into tb3 select id_acount, id_acountid,sum_money  from tb2
insert into tb3 select a.id_acount, a.id_acountid,a.sum_money  from tb1 a left join tb2 b on a.id_acount=b.id_acount  where b.id_acount is nullselect * from tb3drop table tb1,tb2,tb3

解决方案 »

  1.   

    --测试数据
    create table tb1(id int identity(1,1),id_acount char(4),id_acountid char(2),sum_money money)
    insert into tb1 select '0001','00',10
    union all select '0002','00',60
    union all select '0003','00',80
    union all select '0004','00',60
    union all select '0005','00',80
    union all select '0006','00',100create table tb2(id int identity(1,1),id_acount char(4),id_acountid char(2),sum_money money)
    insert into tb2 select '0001','00',1000
    union all select '0003','00',600
    union all select '0005','00',800--生成tb3
    select * 
    --into tb3 
    from tb1 a
    left join tb2 b on a.id_acount=b.id_acountdrop table tb1,tb2
      

  2.   

    大哥,我把你的代码执行了下,得到下面的结果:1 0001 00 10.0000 1 0001 00 1000.0000
    2 0002 00 60.0000 NULL NULL NULL NULL
    3 0003 00 80.0000 2 0003 00 600.0000
    4 0004 00 60.0000 NULL NULL NULL NULL
    5 0005 00 80.0000 3 0005 00 800.0000
    6 0006 00 100.0000 NULL NULL NULL NULL这个表格中的数据仍然没有达到我的要求,我需要的是下面的这个样子:1 0001 00 1000.0000          --这个记录是TB2中的
    2 0002 00 60.0000          --这个是TB1中的
    3 0003 00 600.0000 --这个记录是TB2中的
    4 0004 00 60.0000 --这个是TB1中的
    5 0005 00 800.0000 --这个记录是TB2中的
    6 0006 00 100.0000 --这个是TB1中的
      

  3.   

    remote_peng(一個想做程序員的女孩) 谢谢你的回答!结贴!