热线电话:13121318867

登录
2019-03-01 阅读量: 1152
sql语句分组取前五名

问题描述:

mysql数据库字段如上图所示

按stage_id分组后,按照total由大到小递减取得前5条,

现在每一组有30条,总共有8组

解决方法:

select * from table as a where (select count(distinct(total)) from table as b where a.stage_id = b.stage_id and b.total > a.total) < 5;
5.9738
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子