你可以试试这个,有疑问可HI我。select * from table a where (select count(1) from table b where a.channel_id=b.channel_id and a.time
mysql分组 排序 取前2条
可以写为 select id,channel_id,time from table where group by channel_id order by time desc limit 22011-05-23
你可以试试这个,有疑问可HI我。
select * from table a
where
(select count(1) from table b
where a.channel_id=b.channel_id and a.time<b.time)<2
order by channel_id,time desc
具体原理可参看我空 间的文章
SQL分类下的《取得分组TOP-N测试表与测试数据》2011-05-23
没办法,只能子查询,order by 是对查询之后的数据排序,永远在最后执行,个group by合用一点用都没有,能做的就是子查询提高效率。2012-03-29
exit exit exit exit exit exit2019-02-23