mysql分组排名

SELECT
b.totalTime,
b.status,
b.finishTime as matchTime,
b.new_rank AS rowNo,
a.name
FROM
(
SELECT
match_id,
totalTime,
status,
phone,
finishTime,
IF (
@tmp = a.match_id,@rank :=@rank + 1 ,@rank := 1
) AS new_rank,
@tmp := a.match_id AS tmp
FROM
zap_athlete  a
ORDER BY
a.totalTime  aSC
) b  LEFT JOIN zap_match a on b.match_id=a.id
WHERE
b.match_id in  ( select match_id from zap_athlete where phone=#{phone}) and b.phone =#{phone} and b.totalTime!=0
ORDER BY b.finishTime desc

猜你喜欢

转载自blog.csdn.net/yefan_/article/details/80391808