mysql - Modify column values to that they are in order -
i got special problem i'd solve in sql. need make sure optionorder same questionid goes 0-[any number].
so example rows questionid = 18386, optionorder right 1,2,3,4. need 0,1,2,3.
also if rows 1,2,4, needs 0,1,2
i'm sorry incorrect grammars.
in mysql, can variables:
set @rn := 0; set @q := -1; update table t set optionorder = (case when @q = questionid (@rn := @rn + 1) when (@q := questionid) not null (@rn := 0) else -1 -- should never happen end) order questionid, optionorder;
because of order by
, need set variables outside update
.
Comments
Post a Comment