![](/style/images/good.png)
5
![](/style/images/bad.png)
mysql 分组后的组内排序
source link: http://abcdxyzk.github.io/blog/2021/04/04/mysql-row_number/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
mysql 分组后的组内排序
2021-04-04 21:34:00
https://www.cnblogs.com/hxfcodelife/p/10226934.html
数据库的查询顺序是先分组的,最后才将结果进行排序。 group by XX order by yy 是不行的
用 row_number() over(partition by XX order by YY desc)
select a.Classid,a.English from (select Classid,English,row_number() over(partition by Classid order by English desc) as n from CJ) a where n<=2
https://blog.csdn.net/u014508939/article/details/100561133
用 GROUP_CONCAT, SUBSTRING_INDEX
SELECT SUBSTRING_INDEX(GROUP_CONCAT(id, ORDER BY update_time DESC), ',', 1) FROM goods GROUP BY good_id OEDER by update_time DESC;
Posted by kk
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK