I'm trying to get rank of user in the table with stored time.
RAW SQL query is working fine but I can't make it work as procedure.
SET @rownum := 0;
SELECT rank, user_id, best_time
FROM (
SELECT @rownum := @rownum +1 AS rank,id, best_time, user_id
FROM user_round WHERE round_id=1 ORDER BY best_time ASC
) AS result WHERE user_id = 1
My try to procedure:
BEGIN
DECLARE variable INT DEFAULT 0;
SELECT rank,best_time, user_id
FROM (
SELECT SET variable=variable+1 AS rank, best_time, user_id
FROM database.user_round WHERE round_id=1 ORDER BY best_time ASC
) AS result WHERE user_id = 1;
END