update test5
set [email protected]:=if(@grp=q_id,@srt+1,1),
[email protected]:=q_id
where (0,0)=(select @grp:=0,@srt:=0)
order by q_id, `name`
Imposta necessario "ordina per". La prima colonna in "ordina per" deve essere "q_id".
SET SQL_SAFE_UPDATES = 0;