一:按照某字段排序(時間,總數等),獲取第一條spa
select a.* FROM ( select * from ( select t.*,row_number() over(partition by t.id order by t.createtime desc) rn from table t ) c where rn = 1) a where a.id= '001';--加上where條件是查詢一條,不加是查詢多條
二:若是是獲取時間最新一條數據code
SELECT * FROM table WHERE (id,createtime) IN (SELECT id,MAX(createtime) createtime FROM table GROUP BY id);--獲取時間最新的多條數據 SELECT * FROM table where a.id='018' and createtime=(SELECT MAX(createtime) FROM table where a.id='018');--獲取一條時間最新的數據