标签: mysql sql greatest-n-per-group
我想将分组结果限制为30,但我将所有行分组,然后将其限制为30组。我该怎么做?
SELECT *, COUNT(*) AS COUNT FROM `Posts` GROUP By `Category` LIMIT 30
答案 0 :(得分:10)
SELECT *, COUNT(*) AS COUNT FROM (SELECT * FROM `Posts` LIMIT 30) t GROUP By `Category`