select A.userName, postDate, post from table A inner join (select distinct userName, max(postDate) as maxPostDate from table group by userName) B on A.userName = b.userName and A.postDate = B.maxPostDate
大概是这样
anoymoux
2017 年 8 月 11 日
加一张表 latest_post(userid,postid)
ayumilove
2017 年 8 月 11 日
@CRVV 恩,谢谢。 好多年没用过 mysql 了 ,还以为原生 不支持 over(partition by ~)
quickma
2017 年 8 月 11 日
加表是一个不错的想法,view 也行呀。
noNOno
2017 年 8 月 11 日
select * from (select *,row_number over (partition by userName order by postdate desc ) as rn from table ) where rn=1