分组前的MySQL LIMIT?

时间:2012-02-25 06:01:10

标签: mysql sql greatest-n-per-group

我想将分组结果限制为30,但我将所有行分组,然后将其限制为30组。我该怎么做?

SELECT *, COUNT(*) AS COUNT FROM `Posts` GROUP By `Category` LIMIT 30

1 个答案:

答案 0 :(得分:10)

SELECT *, COUNT(*) AS COUNT FROM (SELECT * FROM `Posts` LIMIT 30) t GROUP By `Category`