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

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

 

select 

case when pid=0 then
case when @prevType=QUETYPE_ID then @rank:=@rank+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

posted @ 2016-05-19 17:38  JIN__JIN  阅读(1635)  评论(0编辑  收藏  举报