select distinct a.productspecname, a.productiontype
  from ps_lothistory a
 where a.oldareaname = 'ASSY'
   and a.oldprocessoperationname = 'AM030'
   and a.eventname in
       ('JobOutProducible', 'ReworkProducible', 'ScrapProducible')
   and a.eventtime between
       to_date('2011-07-14 08:30:00', 'yyyy-mm-dd hh24:mi:ss') and
       to_date('2011-07-15 08:30:00', 'yyyy-mm-dd hh24:mi:ss')
   and a.site = 'CP1'sql语句如上,这个语句的运行速度很慢,要1分钟,请问怎么才能提高它的运行速度呢

解决方案 »

  1.   


    --试试
    SELECT A.PRODUCTSPECNAME, A.PRODUCTIONTYPE
      FROM PS_LOTHISTORY A
     WHERE A.OLDAREANAME = 'ASSY'
       AND A.OLDPROCESSOPERATIONNAME = 'AM030'
       AND A.EVENTNAME IN
           ('JobOutProducible', 'ReworkProducible', 'ScrapProducible')
       AND A.EVENTTIME BETWEEN
           TO_DATE('2011-07-14 08:30:00', 'yyyy-mm-dd hh24:mi:ss') AND
           TO_DATE('2011-07-15 08:30:00', 'yyyy-mm-dd hh24:mi:ss')
       AND A.SITE = 'CP1'
      GROUP BY A.PRODUCTSPECNAME, A.PRODUCTIONTYPE;
      

  2.   

    select  a.productspecname, a.productiontype
      from ps_lothistory a
     where a.oldareaname = 'ASSY'
      and a.oldprocessoperationname = 'AM030'
      and a.eventname in
      ('JobOutProducible', 'ReworkProducible', 'ScrapProducible')
      and a.eventtime between
      to_date('2011-07-14 08:30:00', 'yyyy-mm-dd hh24:mi:ss') and
      to_date('2011-07-15 08:30:00', 'yyyy-mm-dd hh24:mi:ss')
      and a.site = 'CP1'
      and rowid (select max(rowid) from ps_lothistory b where a.productspecname= b.productspecname and a.productiontype = b.a.productiontype)
      

  3.   

    select a.productspecname, a.productiontype
      from ps_lothistory a
     where a.oldareaname = 'ASSY'
      and a.oldprocessoperationname = 'AM030'
      and a.eventname in
      ('JobOutProducible', 'ReworkProducible', 'ScrapProducible')
      and a.eventtime between
      to_date('2011-07-14 08:30:00', 'yyyy-mm-dd hh24:mi:ss') and
      to_date('2011-07-15 08:30:00', 'yyyy-mm-dd hh24:mi:ss')
      and a.site = 'CP1'
      and rowid =  (select max(rowid) from ps_lothistory b where a.productspecname= b.productspecname and a.productiontype = b.a.productiontype)
      

  4.   

    不行啊,上面两个方法都试了,速度还没有原先的语句快啊。这个sql语句是要在存储过程中运行的。
      

  5.   

    表ps_lothistory 的索引有没有?是以哪几个字段建的?
    where语句中的查询条件,尽量要往索引上靠。如果实在没有索引,最好建一下。
    没有索引,就全表扫描了。
      

  6.   

    你起码要给出表结构和其他一些信息,单纯看sql,别人和你得到的信息一样多,没办法进一步优化。