你就去最大的,直接order by取第一条:select * from (select loopid,timestamp from onlinetrafficdata order by timestamp desc) where rownum=1
略改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
timestamp是timpstamp类型的字段名。
直接max就行了吧 不用to_char吧 select loopid,timestamp from onlinetrafficdata where timestamp in (select max(timestamp) From onlinetrafficdata);
select loopid,timestamp from onlinetrafficdata a where not exists (select 1 from onlinetrafficdata where timestamp > a.timestamp) 这样会快点不,至于按分钟还是还是按秒可以先格式化timestamp
建个函数索引吧 create index onlinetrafficdata_index1 on onlinetrafficdata( to_char(timestamp, 'yyyy-mm-dd hh24:mi'));
(select loopid,timestamp from onlinetrafficdata order by timestamp desc)
where rownum=1
(select loopid,timestamp,rank() over (order by to_char(timestamp,'yyyy-mm-dd hh24:mi') desc ) as rnk
from onlinetrafficdata )
where rnk=1
select loopid,timestamp from onlinetrafficdata
where timestamp in (select max(timestamp) From onlinetrafficdata);
max出来的可能精确到毫秒,我这一分钟插入n组数据,每组数据秒数不一样。。
而且我一秒钟可能插入几十条数据
这样会快点不,至于按分钟还是还是按秒可以先格式化timestamp
create index onlinetrafficdata_index1 on onlinetrafficdata( to_char(timestamp, 'yyyy-mm-dd hh24:mi'));