How to use the user defined variable in a way that the value of the variable is reused in the subsequent query in mysql?
Just use it:
SELECT @r := 1 --- 1 SELECT @r := @r + 1 --- 2