select ic02.* from ic02 
minus
select ic02.* from ic01,ic02 where ic01.aac001=ic02.aac001 and SubStr(ic01.aae002,1,4)=ic02.aae001

解决方案 »

  1.   

    select ic02.* from ic02 where ic02.field1 not in (select ic02.field1 from ic01,ic02 where ic01.aac001=ic02.aac001 
    and SubStr(ic01.aae002,1,4)=ic02.aae001)
      

  2.   

    为什么我的not exists不行呢???
    minus 是可以的
      

  3.   

    试试:
     select ic02.* from ic02 where not exists (select * from 
    (select ic02.* from ic01,ic02 where ic01.aac001=ic02.aac001 
    and SubStr(ic01.aae002,1,4)=ic02.aae001) b
    where ic01.aac001=b.aae001
      

  4.   

    试试:
     select ic02.* from ic02 where not exists (select * from 
    (select ic02.* from ic01,ic02 where ic01.aac001=ic02.aac001 
    and SubStr(ic01.aae002,1,4)=ic02.aae001) b
    where ic01.aac001=b.aac001 )
      

  5.   

    你这里用not exists是永远也得不到差集的where后只有一个条件,not exists(...)
    当条件成立,则取ic02的所有记录,当条件不成立则一条记录也取不到
      

  6.   

    取差集最好的办法也就是用minus,不用花时间去想其它的方法了,要不然ORACLE也不用开发出minus来了
      

  7.   

    从性能方面着想,强烈建议版主用minus方法.
    用libin_ftsafe(子陌红尘)的方法:
    select ic02.* from ic02 
    minus
    select ic02.* from ic01,ic02 where ic01.aac001=ic02.aac001 and SubStr(ic01.aae002,1,4)=ic02.aae001速度比用not in或not exist快好几倍,又不易出错!!!
      

  8.   

    select ic02.* from ic02 
    minus
    select ic02.* from ic01,ic02 where ic01.aac001=ic02.aac001 and SubStr(ic01.aae002,1,4)=ic02.aae001