SELECT
tt.id,
( @rowNum := @rowNum + 1 ) AS ranking
FROM
( select 5 as id union all select 4 as id union all select 3 as id union all select 2 as id union all select 1 as id
ORDER BY id
) tt
,( SELECT ( @rowNum := 0 ) ) as e
出處:https://www.cnblogs.com/suheng01/