我正在尝试获取一个分组的结果,每个组仅排前5行。.混淆操作方法。
以下是查询:
SELECT O.rest_brId as BRID, O.`reason` as REASON , count(O.reason) as
OCCURENCES
FROM orders O
WHERE O.status = 4
GROUP BY BRID, REASON
HAVING count(O.reason)
我想要的是每个BRID都具有<= 5行,且TOP 5 MAX号。发生次数
怎么办?谷歌搜索,但感到困惑。
答案 0 :(得分:1)
我无法发表评论,但是您是否不需要先ORDER BY OCCURENCES DESC
然后再LIMIT 5
?