mysql 查询获取排名的方法(绝对有效)

Posted JIN小坏

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 查询获取排名的方法(绝对有效)相关的知识,希望对你有一定的参考价值。

http://blog.csdn.net/k8080880/article/details/11253305

 

select 

case when pid=0 then
case when @prevType=QUETYPE_ID then @rank:[email protected]+1
when @prevType:=QUETYPE_ID then @rank:=1 end
else QUE_SORT end as QUE_SORT2,

A.*

from(
SELECT
0 EXAM_ID,
q.PID,

q.QUE_SORT,

@prevType:=q.QUETYPE_ID

FROM
T_HOME_QUESTION rel left join
T_QUESTION q on (rel.question_id=q.question_id or rel.question_id=q.pid )
WHERE rel.home_id=320 order by QUETYPE_ID,pid
)A,(SELECT @rank:=0, @prevType:=null) B

以上是关于mysql 查询获取排名的方法(绝对有效)的主要内容,如果未能解决你的问题,请参考以下文章

MySQL实现排名查询并指定用户查看排名

如何在mysql中获取这个特定的用户排名查询?

更新 MySQL 表中的排名

MySQL 基于得分和时间的排名

MySQL聚合连接?

MySql - 在复杂查询中获取 rowid / order [关闭]