MySQL获取所有分类的前N条记录

 SELECT a1.* FROM t_content a1
INNER JOIN
(SELECT a.channelId,a.id FROM t_content a LEFT JOIN t_content b
<![CDATA[ ON a.channelId=b.channelId AND a.id<=b.id ]]>
AND a.status=2
GROUP BY a.channelId,a.id
<![CDATA[ HAVING COUNT(b.id)<=10]]>
)b1
ON a1.channelId=b1.channelId AND a1.id=b1.id
ORDER BY a1.channelId,a1.id DESC
posted @ 2016-08-25 11:40  向之礼  阅读(1257)  评论(0编辑  收藏  举报