日期:2014-05-17  浏览次数:20923 次

查询语句很慢,怎么优化呢??
SELECT w.prod_series, e.step_key, SUM (e.qty) qty, '0' AS timeflag,
  e.trx_date
  FROM (SELECT a.step_key, a.qty, a.wo_key,
  (CASE
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 08:30',
  'YYYY/MM/DD HH24:MI:SS')
  AND a.trx_date <
  TO_DATE ('2012-06-13 09:30',
  'YYYY/MM/DD HH24:MI:SS')
  THEN '08:30 -09:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 09:30',
  'YYYY/MM/DD HH24:MI:SS')
  AND a.trx_date <
  TO_DATE ('2012-06-13 10:30',
  'YYYY/MM/DD HH24:MI:SS')
  THEN '09:30 -10:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 10:30',
  'YYYY/MM/DD HH24:MI:SS')
  AND a.trx_date <
  TO_DATE ('2012-06-13 11:30',
  'YYYY/MM/DD HH24:MI:SS' )
  THEN '10:30 -11:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 11:30',
  'YYYY/MM/DD HH24:MI:SS')
  AND a.trx_date <
  TO_DATE ('2012-06-13 12:30',
  'YYYY/MM/DD HH24:MI:SS')
  THEN '11:30 -12:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 12:30',
  'YYYY/MM/DD HH24:MI:SS')
  AND a.trx_date <
  TO_DATE ('2012-06-13 13:30',
  'YYYY/MM/DD HH24:MI:SS')
  THEN '12:30 -13:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 13:30',
  'YYYY/MM/DD HH24:MI:SS' )
  AND a.trx_date <
  TO_DATE ('2012-06-13 14:30',
  'YYYY/MM/DD HH24:MI:SS')
  THEN '13:30 -14:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 14:30',
  'YYYY/MM/DD HH24:MI:SS')
  AND a.trx_date <
  TO_DATE ('2012-06-13 15:30',
  'YYYY/MM/DD HH24:MI:SS')
  THEN '14:30 -15:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 15:30',
  'YYYY/MM/DD HH24:MI:SS')
  AND a.trx_date <
  TO_DATE ('2012-06-13 16:30',
  'YYYY/MM/DD HH24:MI:SS')
  THEN '15:30 -16:30'
  WHEN a.trx_date >=
  TO_DATE ('2012-06-13 16:30',
  'YYYY/MM/DD HH24:MI:SS' )
  AND a.trx_date &l