I am trying to fetch a grouped result, with only top 5 rows for each group.. Confused how to do it..
Here's the query:
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)
What I want is that every BRID to have <= 5 rows, with TOP 5 MAX no. of OCCURENCES
How to do? Googled, but got confused.