select * From ccps_traderecord td left join ccps_creditinfo ci on td.tr_no=ci.ci_tr_no where 1=1 and (
ci.CI_SHA256 in (select distinct ci.CI_SHA256 from ccps_traderecord t left join ccps_creditinfo ci on t.tr_no=ci.ci_tr_no where 1=1 
    and to_date('2013-05-09 17:31:55','yyyy-MM-dd hh24:mi:ss') <= t.TR_DATETIME 
    and to_date('2013-05-16 17:31:55','yyyy-MM-dd hh24:mi:ss') >= t.TR_DATETIME and ci.CI_SHA256 is not null) 
and ci.CI_EMAIL in (select distinct ci.CI_EMAIL from ccps_traderecord t left join ccps_creditinfo ci on t.tr_no=ci.ci_tr_no where 1=1 
    and to_date('2013-05-09 17:31:55','yyyy-MM-dd hh24:mi:ss') <= t.TR_DATETIME 
    and to_date('2013-05-16 17:31:55','yyyy-MM-dd hh24:mi:ss') >= t.TR_DATETIME and ci.CI_EMAIL is not null) 
or ci.CI_IPADDRESS in (select distinct ci.CI_IPADDRESS from ccps_traderecord t left join ccps_creditinfo ci on t.tr_no=ci.ci_tr_no where 1=1 
    and to_date('2013-05-09 17:31:55','yyyy-MM-dd hh24:mi:ss') <= t.TR_DATETIME 
    and to_date('2013-05-16 17:31:55','yyyy-MM-dd hh24:mi:ss') >= t.TR_DATETIME) 
or ci.CI_ADDRESS in (select distinct ci.CI_ADDRESS from ccps_traderecord t left join ccps_creditinfo ci on t.tr_no=ci.ci_tr_no where 1=1 
    and to_date('2013-05-09 17:31:55','yyyy-MM-dd hh24:mi:ss') <= t.TR_DATETIME 
    and to_date('2013-05-16 17:31:55','yyyy-MM-dd hh24:mi:ss') >= t.TR_DATETIME)
) and (
ci.ci_firstname||' '||ci.ci_lastname not in (select distinct ci.ci_firstname||' '||ci.ci_lastname from ccps_traderecord t left join 
    ccps_creditinfo ci on t.tr_no=ci.ci_tr_no where 1=1 and to_date('2013-05-09 17:31:55','yyyy-MM-dd hh24:mi:ss') <= t.TR_DATETIME 
    and to_date('2013-05-16 17:31:55','yyyy-MM-dd hh24:mi:ss') >= t.TR_DATETIME and ci.ci_firstname||' '||ci.ci_lastname is not null) 
and ci.CI_TEL not in (select distinct ci.CI_TEL from ccps_traderecord t left join ccps_creditinfo ci on t.tr_no=ci.ci_tr_no where 1=1 
    and to_date('2013-05-09 17:31:55','yyyy-MM-dd hh24:mi:ss') <= t.TR_DATETIME 
    and to_date('2013-05-16 17:31:55','yyyy-MM-dd hh24:mi:ss') >= t.TR_DATETIME and ci.CI_TEL is not null) 
or ci.CI_ZIPCODE not in (select distinct ci.CI_ZIPCODE from ccps_traderecord t left join ccps_creditinfo ci on t.tr_no=ci.ci_tr_no where 
   1=1 and to_date('2013-05-09 17:31:55','yyyy-MM-dd hh24:mi:ss') <= t.TR_DATETIME 
   and to_date('2013-05-16 17:31:55','yyyy-MM-dd hh24:mi:ss') >= t.TR_DATETIME)
) order by td.TR_DATETIME descoracle,优化

解决方案 »

  1.   

    取ci 的字段 要t表左关联? 时间条件这个反着写不习惯
      

  2.   

    http://blog.csdn.net/qinyu100/article/details/8933013可以参考下,具体还要自己分析分析,这里表结构,索引,数据量都不清楚,很难做出准确的判断
      

  3.   

    执行计划,比给出sql更有意义。另外,你的排版 太不好了,看着头晕
      

  4.   

    描述下你的表的内容,表结构关键信息,表上索引,贴出执行计划,说明一下SQL语句的意义。很多SQL语句其实换个角度来看的话可能会更简单,并不一定是通过优化结构优化参数来完成。
      

  5.   

    如果有兄弟觉得我上面的sql语句排版有些乱的话 ,你可以把他复制到plsql里面,然后自己再排下版,就很清晰了,我在这里没法排版,不好意思
      

  6.   

    从这段看
    ci.ci_firstname||' '||ci.ci_lastname not in (select distinct ci.ci_firstname||' '||ci.ci_lastname 
    1,直接判断不可以吗?还拼接后再折腾?2,不用IN 用 exist, 就可以不用distinct了,而且更快更省