mysql分组查询max值所在的记录

俩方式,一个是分组内先固定好排序

另一个是可以借鉴主键为排序依据的情况下,来用

SELECT max(start_time),pass_state FROM (
    SELECT * FROM `record` ORDER BY id desc
)a

SELECT * FROM `course_record` r
INNER JOIN (SELECT max(id) as id FROM `record` group by f_key_id)b on r.id= b.id

 

posted @ 2022-01-27 14:33  君子笑而不语  阅读(300)  评论(0编辑  收藏  举报