How to shift column data using UPDATE in a MySQL table? -



How to shift column data using UPDATE in a MySQL table? -

i want utilize static-sized table this:

+------+----------+-----------+ | id | col1 | col2 | +------+----------+-----------+ | 1 | | x | +------+----------+-----------+ | 2 | b | y | +------+----------+-----------+ | 3 | c | z | +------+----------+-----------+

is there way shift column info upwards when update [3, col1] example? table should this...

+------+----------+-----------+ | id | col1 | col2 | +------+----------+-----------+ | 1 | b | x | +------+----------+-----------+ | 2 | c | y | +------+----------+-----------+ | 3 | d* | z | +------+----------+-----------+

*new value in [row3, col1] , column info has been shifted up; in advance.

you can update/join:

update table t left bring together table tnext on t.id = tnext.id - 1 set t.col1 = (case when tnext.id null 'd' else tnext.col1 end);

mysql

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -