我有一个这样的sql语句,查询的速度特别的慢,但是我不知道应该怎么样改能快一些,请高手帮忙
select distinct
       t.km,
       t.dh,
       t.jh ,
       t.pzsj ,
       t.sgdw ,
       v.jszbrrq ,
       v.scyxbshrq ,
       (select distinct proctime From wfi_proc where genstepname = '生产运行部作业组调拨' and procnote is null and SELPINID !=7 and rsid =v.wj and rownum=1) as scyxbzyzdb,
       (select distinct proctime From wfi_proc where genstepname = '效益评价' and procnote is null and SELPINID !=7 and rsid = v.wj and rownum=1) as xypj,
       t.xh
  from ddf01 t, ddf_ysjs_new v
 where t.xh = v.WJ

解决方案 »

  1.   

    select distinct
           t.km,
           t.dh,
           t.jh ,
           t.pzsj ,
           t.sgdw ,
           v.jszbrrq ,
           v.scyxbshrq ,
           proctime scyxbzyzdb,
           proctime xypj ,
           t.xh
      from ddf01 t, ddf_ysjs_new v,wfi_proc wp,wfi_proc wp1
     where t.xh = v.WJ
    and wp.rsid=v.wj
    and wp.genstepname = '生产运行部作业组调拨' 
    and wp.procnote is null 
    and wp.SELPINID !=7
    and wp1.rsid=v.wj
    and wp1.genstepname = '效益评价' 
    and wp1.procnote is null 
    and wp1.SELPINID !=7 
      

  2.   

    子查詢,每個行都做兩個子查詢會慢,
    再者要調優最好要看哪些表是大表,哪些是小表,大表靠近From,
    一次能排除多記錄的放後面,SQL執行順序從後往前
      

  3.   

    固定记录的放在where子句的最后
      

  4.   

    select distinct
           t.km,
           t.dh,
           t.jh ,
           t.pzsj ,
           t.sgdw ,
           v.jszbrrq ,
           v.scyxbshrq ,
           proctime scyxbzyzdb,
           proctime xypj ,
           t.xh
      from ddf01 t, ddf_ysjs_new v,wfi_proc wp,wfi_proc wp1
     where t.xh = v.WJ
    and wp.rsid=v.wj
    and wp.genstepname = '生产运行部作业组调拨' 
    and wp.procnote is null 
    and (wp.SELPINID >7 or wp.SELPINID <7)
    and wp1.rsid=v.wj
    and wp1.genstepname = '效益评价' 
    and wp1.procnote is null 
    and (wp1.SELPINID >7 or wp1.SELPINID <7)