现在我碰到这样一个问题。
selec * from T1 where MFG_NO||MUGIOPCD||NO||MUGIYYMM  not in (select MFG_NO||maintain_code||NO||MUGIYYMM from T2)1.T1表的数据有160W条
2.T2表有1000条。当执行的时候太慢了有没有什么好的提速方法,现在查询 大概要2秒。 我一个页面上要调用50次,那就是100秒。实在太久了

解决方案 »

  1.   

    select * from t1
    where not exists (select 1 from t2
                       where t2.MFC_NO=t1.MFC_NO
                         and t2.MUGIOPCD=t1.MUGIOPCD
                         and t2.NO=t1.NO
                         and t2.MUGIYYMM=t1.MUGIYYMM );
      

  2.   

    -- 如果某字段为空值也算相等(根据你的意思:应该是这样的),可以这样写:select * from t1
    where not exists 
      (select 1 from t2
       where ( t2.MFC_NO=t1.MFC_NO or (t1.MFC_NO is null and t2.MFC_NO is null ) )
       and   ( t2.MUGIOPCD=t1.MUGIOPCD or ( t1.MUGIOPCD is null and t2.MUGIOPCD is null ) )
       and   ( t2.NO=t1.NO or ( t1.NO is null and t2.NO is null )
       and   ( t2.MUGIYYMM=t1.MUGIYYMM or ( t1.MUGIYYMM is null and t2.MUGIYYMM is null ) )
      );
      

  3.   

    +1。改成not exists或者左连接,字符串别拼一起了,那样即使有索引也用不到。