//MySQL 8.0写法 select * from( select row_number() over (partition by UserName order by CheckTime desc) as rn,u.* from kq_record u where CheckDate = ‘2018-03-31 00:00:00‘ ) t where t.rn=1 //MySQL 5.7 比如一个用户多条登录记录取最后时间 select max.*, MAX(max.CheckTime) createMax From (select * from kq_record where CheckDate = ‘2020-12-02 00:00:00‘ order by CheckTime desc) max group by UserName,InOrOut