LvYouQian 2016-05-18 09:40 采纳率: 50%
浏览 3588
已采纳

oracle left join 查询右表没有匹配到的数据

oracle left join 查询右表没有匹配到的数据,目前用的是 is null 做的判断,但是效率很慢,各位大神有没有高效一点的方法

select shd.*
from temp_termspastdue tmp join (select s.loan_no,s.ps_due_dt,
loan.cust_id,
loan.loan_grd,
loan.loan_actv_dt,
loan.orig_prcp,
loan.last_due_dt,
loan.OLD_LAST_DUE_DT,
loan.recentpaydt,
loan.typ_rat,
ct.loan_od_grace
from (select loan_no,ps_due_dt from CREDIT_LM_PM_SHD where PP_ER_IND='N' and to_date(ps_due_dt, 'yyyy-MM-dd') >= date '2016-01-01' and (setl_ind<>ps_od_ind or(ps_od_ind='Y' and setl_ind='Y')) ) s
join (select l.loan_no,
l.loan_cont_no,
l.loan_actv_dt,
l.last_due_dt,
l.last_setl_dt recentpaydt,
l.cust_id,
l.loan_grd,
l.Orig_Prcp,
l.OLD_LAST_DUE_DT,
typ.typ_rat
from ods_cmsg_lm_loan l, loan_typ_detail typ
where typ.typ_cde = l.loan_typ
and typ.upl_flg = 1
and typ.typ_rat='2'
and l.loan_sts = 'ACTV') loan
on loan.loan_no = s.loan_no
and s.ps_due_dt > loan.loan_actv_dt
join ods_cmsg_lm_loan_cont ct
on ct.loan_cont_no = loan.loan_cont_no
where to_date(s.ps_due_dt, 'yyyy-MM-dd') + ct.loan_od_grace <i_data_dt
) shd
on tmp.loan_no=shd.loan_no
join s01_tiu_person_all ps
on ps.cust_id = shd.cust_id
left join s01_tiu_trade_all al
on al.account = tmp.loan_no
and to_char(al.billingdate, 'yyyy-MM') =
to_char(to_date(shd.ps_due_dt, 'yyyy-MM-dd'), 'yyyy-MM')
where al.account is null;

  • 写回答

1条回答 默认 最新

  • 中国风 博客专家认证 2016-05-18 10:01
    关注

    如尝试把s01_tiu_trade_all放在条件里
    AND NOT EXISTS(SELECT 1 FROM s01_tiu_trade_all AS al WHERE al.account = tmp.loan_no and to_char(al.billingdate, 'yyyy-MM') =to_char(to_date(shd.ps_due_dt, 'yyyy-MM-dd'), 'yyyy-MM'))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?