查看 这篇 关于如何处理任意复杂分组中前N个问题的
MySQL文章 ;这是好东西。您可以尝试以下方法:
SET @counter = 0;SET @category = '';SELECt *FROM( SELECt @counter := IF(posts.category = @category, @counter + 1, 0) AS counter, @category := posts.category, posts.* FROM ( SELECt * FROM test ORDER BY category, date DESC ) posts) postsHAVINg counter < 2



