各位大虾好 小弟想请教一句SQL语句
就是我有一张表 表里面有两个字段
ID,TIME
time字段的格式是 2008/05/22 11:54:25
我想得到从当天早上9点以后 到下午5点以前 这个时间段内有多少条记录的总数
这个SQL 应该怎样写
谢谢

解决方案 »

  1.   

    where to_number(to_char(time,'hh24')) between 9 and 15
    and time>=trunc(sysdate) 
      

  2.   

    select count(*) from test where time >= trunc(sysdate)+9*60/1440 and timie <= trunc(sysdate)+17*60/1440
      

  3.   

    如果是单日的可以这样
    select count(*)
    from a
    where time between to_date('2008-05-22 09:00:00','yyyy-mm-dd hh24:mi:ss')
    and to_date('2008-05-22 15:00:00','yyyy-mm-dd hh24:mi:ss')
      

  4.   

    如果是多日的,并且时间段有限制
    select count(*)
    from a
    where to_number(to_char(time,'hh24')) between 9 and 15 and 
    time between to_date('2008-05-1 09:00:00','yyyy-mm-dd hh24:mi:ss')
    and to_date('2008-05-22 15:00:00','yyyy-mm-dd hh24:mi:ss')
      

  5.   

    SELECT * FROM TABLENAME 
    WHERE TO_CHAR(SYSDATE,'yyyy/mm/dd hh24:mi:ss') 
    BETWEEN TO_CHAR(SYSDATE,'yyyy/mm/dd')||' 09:00:00' 
    AND TO_CHAR(SYSDATE,'yyyy/mm/dd')||' 15:00:00'  
      

  6.   

    select count(*) from table1 t where to_char(t.time,'yyyyMMddhh24miss') between to_char(sysdate,'yyyyMMdd')||'090000' and to_char(sysdate,'yyyyMMdd')||'170000' 
      

  7.   

    select * from table_name
    where to_char(sysdate,'hh24') between '09' and '17'
      

  8.   

    select count(*) from g$flow
    where to_char(sysdate,'hh24') between '09' and '17'
      

  9.   

    select count(*) from tabel where to_number(to_char(time,'hh24')) between 9 and 17