mysql group by limit

Solutions on MaxInterview for mysql group by limit by the best coders in the world

showing results for - "mysql group by limit"
Adelia
25 Nov 2020
1CREATE TABLE yourtable (
2  year int,
3  id varchar(20),
4  rate decimal(10,2)
5);
6
7SELECT yourtable.*
8FROM   yourtable 
9INNER JOIN (
10  SELECT   id, GROUP_CONCAT(year ORDER BY rate DESC) grouped_year
11  FROM     yourtable
12  GROUP BY id) group_max
13ON yourtable.id = group_max.id AND FIND_IN_SET(year, grouped_year) <=5
14ORDER BY yourtable.id, yourtable.year DESC;