mysql分組查詢最新資料

2021-07-14 03:33:19 字數 494 閱讀 4831

select user_id,sbp,dbp,pulse from p_bp as a, (select max(id) as id, max(measure_at) as measure_at from p_bp as b group by user_id ) as b where a.id=b.id and a.measure_at = b.measure_at;

select id,max(measure_at), max(id) as id from p_bp as b group by user_id

select user_id,sbp,dbp,pulse from (select * from p_bp order by measure_at desc) as a group by user_id;

mysql取分組後最新的一條記錄,下面兩種方法.一種是先篩選 出最大和最新的時間,在連表查詢.一種是先排序,然後在次分組查詢(預設第一條),就是最新的一條資料了

MYSQL 分組查詢最新的資料

第一種前提是資料表設計id自增select from t user where id in select max id from t user group by user id 第二種對子查詢進行limit限制,適用於明確資料量不會超過多少的場景,否則查不到全部資料select from selec...

mysql查詢group by分組最新記錄資料

先group by得到分組每乙個的max id 即是最新記錄,之後通過inner join關聯得到最新記錄表。執行效率 0.031 sec select b.from table name b inner join select max id as id from table name group ...

JPA查詢分組裡的最新資料

如題,用到分組查詢,並且要求是每組的最新一條資料,見 如下 query select d from realtimedata d where d.id in select max id from realtimedata group by simcard and d.simcard in selec...