My table looks like that:
Field | Type |
---|---|
id | int |
user_id | int |
date | datetime |
points | int |
With this query SELECT SUM(points) AS total, DATE_FORMAT(date,'%Y') AS year FROM table WHERE user_id = 2 GROUP BY yearmonth ORDER BY year ASC
I got sum of all points grouped by year.
I would like to take only five highest orders per group (instead of all from this query).
I was trying to find the answer via search, but I can't find the way to get things to work. I know it must be something with row_number, but I can't get it to work. Mysql is 5.7.
Can somebody point me in the right direction?