MySQL8.0跟5.7分组查询表所有字段

//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

 

MySQL8.0跟5.7分组查询表所有字段

上一篇:sql批量生成showdocs数据字典的md文档


下一篇:struts2.5+框架使用通配符与动态方法