数据库
首页 > 数据库> > sql,按照时间排序,取前N条

sql,按照时间排序,取前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;

 

标签:TEMPERATURE,sql,取前,TH,TIME,排序,SELECT
来源: https://www.cnblogs.com/dk1024/p/11057720.html