mysql查询总成绩的前3名学生信息
发布日期:2025-04-17 23:59:49 浏览次数:17 分类:精选文章

本文共 627 字,大约阅读时间需要 2 分钟。

查询总成绩的前3名学生信息

以下是基于MySQL数据库查询前3名学生信息的解决方案

MySQL 8.0+版本

使用窗口函数实现

select id, status, @rank1 := @rank1 + 1, @rank := case when @popularity = status then @rank when @popularity := status then @rank1 end as rank from s_working_confition_file_info, (select @rank := 0, @popularity := null, @rank1 := 0) init order by status desc;

MySQL 8.0下

基于窗口函数的实现

该查询通过窗口函数计算了前3名学生的排名信息

select id, status, @rank1 := @rank1 + 1, @rank := case when @popularity = status then @rank when @popularity := status then @rank1 end as rank from s_working_confition_file_info, (select @rank := 0, @popularity := null, @rank1 := 0) init order by status desc;
上一篇:mysql查询慢排查
下一篇:mysql查询储存过程,函数,触发过程

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2026年06月05日 04时00分00秒