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.

enter image description here

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

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -