*****************sql语句求简化,求速度****************
本帖最后由 reyreoitoo 于 2013-12-16 11:37:42 编辑
select loopid,timestamp from onlinetrafficdata
where max(to_char(timestamp,'yyyy-mm-dd hh24:mi') in (select max(to_char(timestamp,'yyyy-mm-dd hh24:mi'))From onlinetrafficdata);
------解决方案--------------------略改
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
------解决方案--------------------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'));