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

oracle 求两表数据去重复语句优化
sql如下,此条sql已经效率很低,求教效率搞的sql语句。谢谢各位!
SQL code
SELECT *
  FROM LCD29 L
 WHERE L.LDCD291 >= TRUNC(SYSDATE, 'dd')
   AND L.GDAB056 NOT IN
       (SELECT B.BD_DATA5
          FROM HR_COMBOOKDATE B
         WHERE B.BD_DATE >= TRUNC(SYSDATE, 'dd')
           AND TRUNC(L.LDCD291, 'dd') = TRUNC(B.BD_DATE, 'dd'));


分不多,还请各位赐教!

------解决方案--------------------
SQL code

SELECT L.*
  FROM LCD29 L
  inner join HR_COMBOOKDATE B on TRUNC(L.LDCD291, 'dd') = TRUNC(B.BD_DATE, 'dd') AND L.GDAB056 = B.BD_DATA5
 WHERE L.LDCD291 >= TRUNC(SYSDATE, 'dd')
   and B.BD_DATE >= TRUNC(SYSDATE, 'dd');

------解决方案--------------------
SELECT 1更多的时候是用在NOT EXISTS,即不存在,不存在 符合 
FROM HR_COMBOOKDATE B
 WHERE B.BD_DATE >= TRUNC(SYSDATE, 'dd')
……
这些关联条件的记录。为了迎合sql语法,需要select一个字段,那么就select 1吧,当然,select 2 也可以。