select a1.* from users a1
inner join
(select a.username,a.rowno from users a left join users b
on a.username=b.username and a.rowno<=b.rowno
group by a.username,a.rowno
having count(b.rowno)<=2
)b1
on a1.username=b1.username and a1.rowno=b1.rowno
order by a1.username,a1.rowno desc
通过连接查询,但是需要有行号
版权声明:本文为sinat_16945319原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。