1. 程式人生 > >oracle sql 語句巢狀子查詢 查詢速度慢

oracle sql 語句巢狀子查詢 查詢速度慢

select
       ----慢------------------
        (select count(*)
          from (select pe.personid, pe.pgd_sheetid
          --------select * from WXU_NN_T_PG_PERSON t where t.flag != '4'  全表掃描  效率慢
                  from (select * from WXU_NN_T_PG_PERSON t where t.flag != '4') pe
                 group by pe.personid, pe.pgd_sheetid) y
         where y.pgd_sheetid = p.id) zyrs,
       ------快------------
       (select count(distinct t.personid)
          from WXU_NN_T_PG_PERSON t
         WHERE t.flag != '4'
           and t.pgd_sheetid = p.id) zyrs2

  from wxu_t_tc_import t1,
       wxu_t_tc_wc     t2,
       wxu_t_sdsq      t3,
       SYS_T_ORG       s,
       wxu_t_jxssq     t4,
       wxu_nn_t_pg     p
 where 1 = 1
   and t1.isdiscard = '0'
   and t1.id = t2.wxid(+)
   and t1.id = t3.TCID(+)
   and t1.id = t4.TCID(+)
   and (t1.zrgqid = s.id or (t1.zrgqid is null and t1.phzrgqid = s.id))
   and t1.id = p.tcid(+)
   and (t1.pipeistate = '2' or t1.pipeistate is null)
   and (t1.sgtype != '-1' or t1.sgtype is null)
   and (s.orgnum like '01021003%' or exists
        (select 0
           from wxu_t_tc_plan tp, SYS_T_ORG s1, wxu_t_tc_import_week tw
          where tw.id = t1.planid
            and tp.id = tw.planid
            and s1.id = tp.zycj_orgid
            and '01021003' like s1.orgnum || '%'))
   and t1.workdate >= '2017-08-12'
   and t1.workdate <= '2017-09-13'
   and t1.plantype != '2'

 order by t1.workdate, t1.seq