There are 3 columns in the database. It is necessary to shift the entries in column 2 to 1 row.

set @x:=1; update test_sql.a123 set `2` = (select `1` from (select `1`, `ind_date` from test_sql.a123) as `e` where `ind_date` = @x+1) where `ind_date` = (@x:=@x+1); 

However, the result of the work confuses:

enter image description here

For some reason, iterations 1 and 2 can be ignored?

PS: If you initially set set @x: = 0, then the result of the work is all the null lines except the 1st.

  • For some reason, iterations 1 and 2 can be ignored? The order of evaluation of expressions is not defined. - Akina
  • @Akina Please advise some intelligible article / literature where you can read about the order of evaluation of expressions in mysql and how it can be determined / defined - Sergey
  • where you can read about the order of evaluation of expressions dev.mysql.com/doc/refman/5.7/en and dev.mysql.com/doc/internals/en how you can define / specify Yes in general, probably, except that the expressions of the materializing subquery are considered before the expressions of the main query ... - Akina

1 answer 1

 UPDATE a123 t1, a123 t2 SET t1.`2` = t2.`2` WHERE t1.ind_date = t2.ind_date - 1