SELECT c.* FROM (SELECT
@rownum :=@rownum + 1 AS rownum,
IF (
@total = total ,@rank ,@rank :=@rownum
) AS rank ,@total := total AS score ,A.* FROM(
SELECT
total_point AS total,user_id,name,star_level,head_img,data_month,dispatch_company
FROM
user_info
<where>
<if test="request.starLevel != null">
and star_level = #{request.starLevel}
</if>
<if test="request.country != null and request.country != '' ">
and country = #{request.country}
</if>
<if test="request.street != null and request.street != '' ">
and FIND_IN_SET(#{request.street},street)
</if>
<if test="request.attribute != null">
and attribute = #{request.attribute}
</if>
<if test="request.dataMonth != null and request.dataMonth != '' ">
and data_month = #{request.dataMonth}
</if>
</where>
ORDER BY
total_point DESC
) A,
(
SELECT
@rank := 0 ,@rownum := 0 ,@total := NULL
) B) c
<if test="request.start != null and request.end != null">
where rownum >=#{request.start} and rownum <=#{request.end}
</if>
排序效果如图: