本帖最后由 mirsvip 于 2011-11-07 10:59:45 编辑

解决方案 »

  1.   

    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;
      

  2.   


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

  3.   


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

  4.   


    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-04 00:00', 'YYYY-mm-dd hh24:mi') 
       and a.time < to_date('2011-11-16 00:00', 'YYYY-mm-dd hh24:mi')
       and to_char(a.time,'hh24:mi') between '08:30' and '09:00' ;
      

  5.   

    貌似SQL语句无法从数据库中查询出符合这种条件的记录,用存储过程可以实现。
    或者从数据库中查询出某些天的记录,然后在编程语言中对小时分进行字符串解析
    来确定是否为符合条件的记录。
      

  6.   

    这个方法非常值得学习to_char(a.time,'hh24:mi')
      

  7.   

    4楼的不行。
    你确定在这个时间区间内会有数据??
       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')
      

  8.   

    between and 可以实现呀。
      

  9.   

    SELECT 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 00:00', 'YYYY-mm-dd hh24:mi') 
       AND 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' ;