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

问个时间查询问题
怎么查某表一次性从2011-10-15号到2011-11-04号的08:30到09:00的全部记录
这样写只能查出这一天的,怎么才能一次性查出呢 ??
SQL code
select distinct a.test, a.test2, a.test3, a.test4,a.time
  from testtime a
 where a.test1 in ('11', '22')
   and a.time between to_date('2011-10-15 08:30', 'YYYY-mm-dd hh24:mi') and
       to_date('2011-10-15 09:00', 'YYYY-mm-dd hh24:mi')



------解决方案--------------------
SQL code

select distinct a.test, a.test2, a.test3, a.test4,a.time
  from testtime a
 where a.test1 in ('11', '22')
   and a.time >= to_date('2011-10-15 00:00', 'YYYY-mm-dd hh24:mi') 
   and a.time < to_date('2011-11-05 00:00', 'YYYY-mm-dd hh24:mi')
   and to_char(a.time,'hh24:mi') between '08:30' and '09:00' ;