mysql 中group by分组查询最新记录

mysql 中group by分组查询最新记录

mysql5.5

select DISTINCT t.uid from (
    select * from table_name order by create_time desc
 
) as t
group by t.uid;

mysql5.7

select DISTINCT t.uid from (
    select * from table_name order by create_time desc limit 100000
) as t
group by t.uid;

比如说查询文章表中所有用户发表文章的数量及最新的一篇文章

select DISTINCT t.uid,count(*) as  num,t.id,t.title,t.atime from (select * from bfw_article order by atime desc) as t group by t.uid



{{collectdata}}

网友评论0

阿里云香港主机,免备案大优惠 打开浏览器开发html,体验云开发的乐趣bfweditor 打开浏览器即可开发php,bfwstudio
其他文章