首页 > 代码库 > 查询语句,按照时间排序,取前N条

查询语句,按照时间排序,取前N条

mysql:
SELECT * from 
(SELECT H_TEMPERATURE,TH_TIME FROM wenshidu 
WHERE TH_TIME <= STR_TO_DATE(‘2016-03-16 10:04:52‘,‘%Y-%m-%d %H:%i:%s‘)
order by  TH_TIME desc)  as total limit 0,8;

oracle:
SELECT * from 
(SELECT H_HUMIDITY FROM HOME_MONITOR 
WHERE H_TIME <= to_date( ‘ 2016-03-01 10:04:52 ‘ ,‘yyyy-MM-dd HH24:mi:ss‘)   
order by  H_TIME desc ) where rownum<=8;


来自为知笔记(Wiz)


查询语句,按照时间排序,取前N条