重复指A,B,C重复?insert into TA
select t.a,t.b,t.c from TB t where not exists(select 1 from TB a = t.a and b = t.b and c = t.c)

解决方案 »

  1.   

    如果要把D,E也加进去.
    先把表TA加两字段.
    alter table ta ...
    go
    insert into TA
    select t.* from TB t where not exists(select 1 from TB a = t.a and b = t.b and c = t.c)
      

  2.   


    create table #t1 (a int ,b int,c int)create table #t2 (a int ,b int,c int,d int, e int)
    insert into #t2 select 1,1,1,1,1
    insert into #t2 select 1,1,2,1,1
    insert into #t2 select 1,1,2,1,5
    insert into #t2 select 2,1,2,1,1
    insert into #t2 select 3,2,2,1,1
    insert into #t2 select 4,2,2,1,1
    insert into #t2 select 5,3,2,1,1
    insert into #t2 select 7,2,2,1,1
    insert into #t2 select 7,3,2,1,1insert into #t1(a,b,c)
    select a,b,c from #t2 where not exists(select * from #t1 where #t2.a=#t1.a and #t2.b=#t1.b and #t2.c=#t1.c) group by a,b,c
    select * from #t1