表结构如上;怎么取出每个用户的2条评论记录;
解决方案
40
select id,content,user_id from ( select t1.*, (select count(*) from tb t2 where t1.user_id = t2.user_id and t1.id>=t2.id) rn from tb t1 )t where rn <= 2
40
select id,content,user_id from ( select t1.*, (select count(*) from tb t2 where t1.user_id = t2.user_id and t1.id>=t2.id) rn from tb t1 )t where rn <= 2