本帖最后由 reyreoitoo 于 2013-12-16 11:37:42 编辑

解决方案 »

  1.   

    你就去最大的,直接order by取第一条:select * from 
    (select loopid,timestamp from onlinetrafficdata order by timestamp desc) 
    where rownum=1
      

  2.   

    略改select * from 
    (select loopid,timestamp,rank() over (order by to_char(timestamp,'yyyy-mm-dd hh24:mi') desc ) as rnk 
    from onlinetrafficdata ) 
    where rnk=1
      

  3.   

    timestamp是timpstamp类型的字段名。
      

  4.   

    直接max就行了吧 不用to_char吧
    select loopid,timestamp from onlinetrafficdata
      where timestamp in (select max(timestamp) From onlinetrafficdata);  
      

  5.   

    补充,我要取一组数据
    max出来的可能精确到毫秒,我这一分钟插入n组数据,每组数据秒数不一样。。
    而且我一秒钟可能插入几十条数据
      

  6.   

    select loopid,timestamp from onlinetrafficdata a where not exists (select 1 from onlinetrafficdata where timestamp > a.timestamp)
    这样会快点不,至于按分钟还是还是按秒可以先格式化timestamp
      

  7.   

    建个函数索引吧
    create  index onlinetrafficdata_index1  on  onlinetrafficdata( to_char(timestamp, 'yyyy-mm-dd hh24:mi'));