在oracle8i中有一表记载了销售记录,现在想查询某个日期以后没有再销售的客户记录请教有最优化的语句吗?
表:xs :khid(客户khid)  、 xsrq(销售日期)等其他销售信息大概有800多万条记录,用以下语句搜索时间很长请教有更好的语句吗? select * from xs a where khid
    not in
(select DISTINCT kuid from jyz_xs where khid=a.kuid xsrq>'2007/03/05' )

解决方案 »

  1.   

    select * from xs a 
    where not exists
    (select DISTINCT khid from xs where khid=a.khid  and xsrq>'2007/03/05' )
    ---或者
    select a.* from xs a,(select * from xs) b 
    where a.khid(+)=b.khid  and b.xsrq>'2007/03/05' 
          and a.khid is null)不知道哪种更好,或者有其他方法
    试试吧
      

  2.   

    select * from xs a
    where not exists
    (select null from xs where khid=a.khid and xsrq>'2007/03/05' )
      

  3.   

    都尝试了,始终查不出来啊。用sqlplus都查不到,只有rowsnum>50才能提出来请教如类似的海量对比查询都采用什么方法?
      

  4.   

    --表xs及jyz_xs的khid字段均要建索引 select * form xs a
    minus
     select a.* from xs a,jyz_xs b where a.khid=b.kuid and b.xsrq>'2007/03/05' 
      

  5.   

    建个索引试一下,SQL语句用NOT EXISTS  代替 NOT IN