标签:
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  
标签:
原文地址:http://www.cnblogs.com/jcz1206/p/5509147.html