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-08-11 10:50:45 +08:00
加一张表 latest_post(userid,postid)
ayumilove
2017-08-11 11:11:44 +08:00
@CRVV 恩,谢谢。 好多年没用过 mysql 了 ,还以为原生 不支持 over(partition by ~)
x7395759
2017-08-11 11:47:20 +08:00
加表是一个不错的想法,view 也行呀。
noNOno
2017-08-11 11:55:03 +08:00
select * from (select *,row_number over (partition by userName order by postdate desc ) as rn from table ) where rn=1