insert into table_b 
select * from TABLE_A a
where a.id <> (select max(b.id) from TABLE_B b where a.code = b.code);

解决方案 »

  1.   

    不好意思,刚才写错了,更正如下:insert into TABLE_B 
    select * from TABLE_A a
    where a.id <> (select max(b.id) from TABLE_A b where a.code = b.code);
      

  2.   

    insert into table_b(id,code,name)
    (
    select id,code,name from table_a where rowid in
    (select max(rowid) from table_a group by code)
    )
      

  3.   

    比较复杂,但应该正确!insert into TABLE_B 
    select * from TABLE_A a
    where a.id = (select min(b.id) from TABLE_A b where a.code = b.code)
    minus
    select * from TABLE_A c
    where c.id = (select max(d.id) from TABLE_A d where c.code = d.code);
      

  4.   

    insert into table_b(id,code,name)
    select min(id) min_id,code,(select name from table_a t1 where t1.id = min_id)
      from table_a group by code
      

  5.   

    对不起大家,是我没有描述清楚!
    TABLE_A中的字段id类型为字符型,而且,它的值一般都是字符串,如:“aaa”,“bbb”,“ccc”等;而不是依次递增的数字。
    所以,用id来判断,恐怕不行丫。