查询总成绩的前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;