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'))
uj5u.com熱心網友回復:
這樣會取到相同時間的資料么?uj5u.com熱心網友回復:
collect_date 有索引嗎?有索引的話應該不會太慢,感覺你的記錄選擇性應該比較高in 可以換成 =
union 可以換成 UNION ALL
uj5u.com熱心網友回復:
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 上存在合理的索引效率會更高些
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/113603.html
標籤:開發
