select id,val,
@pos := if(@prev<>val,@pos+1,@pos) as pos,
@prev := val as val
from table,(select @pos:=0,@prev:='') as r order by val
Concordo com outros conselhos de que seria melhor fazer isso no nível do aplicativo.
select id,val,
@pos := if(@prev<>val,@pos+1,@pos) as pos,
@prev := val as val
from table,(select @pos:=0,@prev:='') as r order by val