explain select t.n from
(
select @n:=(coalesce(@n,0))+1 as n ,id from (select @n:=0 ) t ,student
where id = 342 order by created_at score
) t where t.id = 301 ;
查询学生301 在学生按分数排行中所在的排位
本文介绍了一种使用SQL查询特定学生在所有学生中的排名的方法。通过自定义变量和子查询的方式,可以有效地获取学生301在分数排行中的位置。
explain select t.n from
(
select @n:=(coalesce(@n,0))+1 as n ,id from (select @n:=0 ) t ,student
where id = 342 order by created_at score
) t where t.id = 301 ;
查询学生301 在学生按分数排行中所在的排位
5576
4186
844

被折叠的 条评论
为什么被折叠?