在Oracle中,我想查系统时间一天的数据,使用这个语句
select * from tablename
where create_time>SYSDATE-1
and create_time<SYSDATE
我想查昨天00:00到今天00:00的sql怎么写,
或者我想查前天08:00到今天08:00的sql怎么写,当然不能写具体时间,因为每次我都查这种数据

解决方案 »

  1.   

    select * from tablename 
    where create_time>= trunc(SYSDATE-1) 
    and create_time <trunc(SYSDATE )
      

  2.   

    select * from tablename 
    where create_time> trunc(SYSDATE-1)+ 8/24
    and create_time < trunc(SYSDATE) + 8/24
      

  3.   

    select * from tablename 
    where create_time>to_date('20090103 00:00:00','yyyymmdd hh24:mi:ss')
    and create_time <to_date(20090104 00:00:00','yyyymmdd hh24:mi:ss')想定时查询出数据,做日志备份或做其他处理,那就写个job
    定时运行
      

  4.   

    select * from tablename 
    where create_time>= trunc(SYSDATE-1) 
    and create_time <trunc(SYSDATE )select * from tablename 
    where create_time> trunc(SYSDATE-1)+ 8/24 
    and create_time < trunc(SYSDATE) + 8/24
    顶!
      

  5.   

    -----------------------------------
    再进一步,我要查一周的数据、一个月的数据怎么做?
    一周是固定的
    select * from tablename 
    where create_time> trunc(SYSDATE-7)+ 8/24 
    and create_time < trunc(SYSDATE) + 8/24 
    那一个月的数据怎么查?
    比如我查上个月8号到这个月8号的数据?
      

  6.   

    create_time >= to_date(to_char(sysdate,'yyyy') || to_char(sysdate,'mm')-1 || '08' ,'yyyy-mm-dd')  and
    create_time < to_date(to_char(sysdate,'yyyy') || to_char(sysdate,'mm') 
    || '08' || '000000','yyyy-mm-dd');
    注:时间范围[2009-10-08 00:00:00--2009-11-07 23:59:59]
      

  7.   

    select * from tablename t where trunc(t.create_time-to_date('2009-11-02 11:11:11','yyyy-mm-dd hh:mi:ss'))<1 and trunc(t.create_time-to_date('2009-11-02 11:11:11','yyyy-mm-dd hh:mi:ss'))>0;  
      

  8.   

    select * from tablename
    where create_time 
    between add_months(to_date(to_char(sysdate,'yyyymm')||'08','yyyymmdd'),-1)
    and to_date(to_char(sysdate,'yyyymm')||'08','yyyymmdd');
      

  9.   

    这里 的  create_time   是表中自己添加的字段 是吗?