查询返回每个 id 的前 5
SELECT yourtable.* FROM yourtable INNER JOIN ( SELECT id, GROUP_CONCAT(year ORDER BY rate DESC) grouped_year FROM yourtable GROUP BY id) group_max ON yourtable.id = group_max.id AND FIND_IN_SET(year, grouped_year) BETWEEN 1 AND 5 ORDER BY yourtable.id, yourtable.year DESC;
1
wqzjk393 2018-03-29 19:29:27 +08:00 via iPhone
没仔细看代码…但是分组排序不是有 row over partition 的么…
|