遇到个问题   怎样取得最近一天数据       有个时间字段   TS             

解决方案 »

  1.   

    select * from tab where ts>=trunc(sysdate)-1
      

  2.   

    select * from 表名 where TS between '日期' and '日期'
      

  3.   

    select * from table where versions between timestamp to_timestamp(trunc(sysdate)+1/86400,'yyyymmdd') and to_timestamp(trunc(sysdate+1)-1/86400,'yyyymmdd') ;
      

  4.   

    select *
    from (select a.*,row_number over(order by ts desc) rn from tb)  where a.rn=1
      

  5.   

    上面的格式写错了:
    这个试试
    select * from table where versions between timestamp to_timestamp(trunc(sysdate)+1/86400,'yyyymmdd hh24:mi:ss') and to_timestamp(trunc(sysdate+1)-1/86400,'yyyymmdd hh24:mi:ss') ;
      

  6.   

    -- 最近一天的:直接用 sysdate-1 就OK啦!
    -- (即24个小时前,到现在的数据,如果你的时间字段,没有比当前时间还大的数据记录行在在的话)
    select * from tab where ts>= sysdate-1;
      

  7.   

    楼上的SQL语句获得的数据不准确,还是用我的吧
      

  8.   

    或者这样:
    select * from tab where ts between trunc(sysdate)+1/86400 and trunc(sysdate+1)-1/86400 ;
      

  9.   

    select * from (select a.*,row_number() over(order by ts desc) rn from tb)  where rn=1
      

  10.   

    oracle 不太会!写出的语句不要笑话我昂...
    不过我的理解是这样的:
    例如:你最近一次(天?)吸烟是在什么时候?
    select * from tb where f_date=(select max(TS) from tb )
      

  11.   

    select * from (select *  from tb order by TS desc ) where ROWNUM=1