While programming SQL statements for ranking generation on speed-kini.de, I found out that local counter variables in SQL statements may no act as intended. Especially if you combine a counter variable with ‘order by‘in the same statement. You can fix it by wrapping your Select statement in a way that the counter variable doesn’t interfere with any ordering:
SELECT @runtot := @runtot + 1 AS 'Rang ', t.* FROM ( SELECT [...]) t, (SELECT @runtot := 0) r;