博客
关于我
mysql查询总成绩的前3名学生信息
阅读量:788 次
发布时间:2023-02-12

本文共 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;

转载地址:http://sidfk.baihongyu.com/

你可能感兴趣的文章
mysql常用命令
查看>>
MySQL常用指令集
查看>>
mysql常用操作
查看>>
MySQL常用日期格式转换函数、字符串函数、聚合函数详
查看>>
MySQL常见错误分析与解决方法总结
查看>>
MySQL底层概述—2.InnoDB磁盘结构
查看>>
MySQL底层概述—3.InnoDB线程模型
查看>>
MySQL底层概述—5.InnoDB参数优化
查看>>
MySQL底层概述—6.索引原理
查看>>
MySQL底层概述—7.优化原则及慢查询
查看>>
MySQL底层概述—8.JOIN排序索引优化
查看>>
MySQL底层概述—9.ACID与事务
查看>>
Mysql建立中英文全文索引(mysql5.7以上)
查看>>
mysql建立索引的几大原则
查看>>
Mysql建表中的 “FEDERATED 引擎连接失败 - Server Name Doesn‘t Exist“ 解决方法
查看>>
MySQL开源工具推荐,有了它我卸了珍藏多年Nactive!
查看>>
MySQL异步操作在C++中的应用
查看>>
Mysql当前列的值等于上一行的值累加前一列的值
查看>>
MySQL当查询的时候有多个结果,但需要返回一条的情况用GROUP_CONCAT拼接
查看>>
MySQL必知必会(组合Where子句,Not和In操作符)
查看>>