日期:2014-05-17  浏览次数:20729 次

请教最为优化的查询语句。
在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 '   )


------解决方案--------------------
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)

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