我这有一条sql语句,请高手来优化!!奖励分只是其次,主要是想看看能否有高手可以解决这个问题~

探索求知 2013-05-16 05:45:47
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 desc
...全文
233 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyf0130 2013-05-23
  • 打赏
  • 举报
回复
从这段看 ci.ci_firstname||' '||ci.ci_lastname not in (select distinct ci.ci_firstname||' '||ci.ci_lastname 1,直接判断不可以吗?还拼接后再折腾? 2,不用IN 用 exist, 就可以不用distinct了,而且更快更省
探索求知 2013-05-22
  • 打赏
  • 举报
回复
如果有兄弟觉得我上面的sql语句排版有些乱的话 ,你可以把他复制到plsql里面,然后自己再排下版,就很清晰了,我在这里没法排版,不好意思
探索求知 2013-05-22
  • 打赏
  • 举报
回复
好吧,我说出我的sql语句要的目的。 ccps_traderecord 表是交易记录表,ccps_creditinfo 是信用卡表,两张表根据流水订单号字段关联, CI_SHA256 是加密信用卡号,CI_EMAIL 加密卡号,CI_IPADDRESS ip地址,CI_ADDRESS 持卡人地址,ci.ci_firstname||' '||ci.ci_lastname 是拼接的持卡人姓名,CI_TEL 持卡人电话,持卡人邮编,…… 其实还有很多字段,以上列出的这些字段的说明都是信用卡表的字段,相信你们看一下命名格式就不难猜出,交易记录表的字段很多,有一百多个,所以在这里就不详细列出了,嗯,我在这里说一下我想要的目的,现在我筛选出近一周做过交易的持卡人在近半年内还做过哪些其他的交易,当然,你可以把这一周的交易理解为“原始交易”,就是根据这些“原始交易”去关联出在这半年同一持卡人做过的其他的交易,同一持卡人判断的依据,相同卡号或者相同邮箱或者相同ip地址或者相同持卡人地址或者相同邮编
rabitsky 2013-05-21
  • 打赏
  • 举报
回复
太乱了,没有格式,看着头疼
vanjayhsu 2013-05-21
  • 打赏
  • 举报
回复
描述下你的表的内容,表结构关键信息,表上索引,贴出执行计划,说明一下SQL语句的意义。很多SQL语句其实换个角度来看的话可能会更简单,并不一定是通过优化结构优化参数来完成。
u010412956 2013-05-20
  • 打赏
  • 举报
回复
执行计划,比给出sql更有意义。 另外,你的排版 太不好了,看着头晕
luckman100 2013-05-20
  • 打赏
  • 举报
回复
http://blog.csdn.net/qinyu100/article/details/8933013可以参考下,具体还要自己分析分析,这里表结构,索引,数据量都不清楚,很难做出准确的判断
探索求知 2013-05-16
  • 打赏
  • 举报
回复
怎么不习惯?就是简单的左连接 再加上一些条件而已
NIan_jun 2013-05-16
  • 打赏
  • 举报
回复
取ci 的字段 要t表左关联? 时间条件这个反着写不习惯

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧