select t.*
  from MONITOR_TEST t
 where t.collect_date in
       (select max(collect_date)
          from MONITOR_TEST
         where collect_date < to_date('2016-11-08', 'yyyy-mm-dd')
           and collect_date > to_date('2016-11-04', 'yyyy-mm-dd'))
 union 
 select t.*
  from MONITOR_TEST t
 where t.collect_date in
       (select min(collect_date)
          from MONITOR_TEST
         where collect_date < to_date('2016-11-08', 'yyyy-mm-dd')
           and collect_date > to_date('2016-11-04', 'yyyy-mm-dd'))

解决方案 »

  1.   

    collect_date  有索引吗?有索引的话应该不会太慢,感觉你的记录选择性应该比较高
    in 可以换成 =
    union 可以换成 UNION ALL
      

  2.   

    1、把最大和最小放在一起读出来
    select max(collect_date),min(collect_date)
              from MONITOR_TEST
             where collect_date < to_date('2016-11-08', 'yyyy-mm-dd')
               and collect_date > to_date('2016-11-04', 'yyyy-mm-dd')
    然后再去比较业务
    2、collect_date 上存在合理的索引效率会更高些