+ -
当前位置:首页 → 问答吧 → 问个时间查询问题

问个时间查询问题

时间:2011-11-07

来源:互联网

怎么查某表一次性从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')

作者: mirsvip   发布时间: 2011-11-07

多写几个or 试试

作者: psufnxk2000   发布时间: 2011-11-07

select distinct a.test, a.test2, a.test3, a.test4,a.time
  from testtime a, 
  (select to_date('20111015083000', 'yyyymmddhh24miss')+rownum-1 as begintime, 
to_date('20111015090000', 'yyyymmddhh24miss')+rownum-1 as endtime
from dual
connect by rownum<=to_date('20111104', 'yyyymmdd')-to_date('20111015', 'yyyymmdd')
)b
where a.test1 in ('11', '22')
  and a.time between b.begintime and b.endtime;

作者: yixilan   发布时间: 2011-11-07

SQL code

where trunc(a.time,'dd') between to_date('2011-10-15', 'YYYY-mm-dd') and  to_date('2011-11-04', 'YYYY-mm-dd')
and
a.time-trunc(a.time,'dd') between to_date('2011-10-15 08:30', 'YYYY-mm-dd hh24:mi')-to_date('2011-10-15', 'YYYY-mm-dd') and to_date('2011-10-15 09:00', 'YYYY-mm-dd hh24:mi')-to_date('2011-10-15', 'YYYY-mm-dd')

作者: funfenffun   发布时间: 2011-11-07

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' ;


作者: xiaobn_cn   发布时间: 2011-11-07