美文网首页
mysql查询表中日期最大的那条数据

mysql查询表中日期最大的那条数据

作者: 指尖听音 | 来源:发表于2019-12-23 14:47 被阅读0次

数据库中有这样的一张表,现在要查询日期最大的那条数据。


file

直接写sql语句如下:

select name,max(gmt_create) from user

得到结果:


file

但是这样输出结果并不正确,name的值不对。
修改sql语句如下:

select a.name,max(a.gmt_create) from user a,
(select name,max(gmt_create) max_day from user ) b 
where a.gmt_create=b.max_day

得到结果:


file

显然,此时输出结果正确

相关文章

网友评论

      本文标题:mysql查询表中日期最大的那条数据

      本文链接:https://www.haomeiwen.com/subject/mtiznctx.html