How to shift column data using UPDATE in a MySQL table? -
I want to use a fixed-size table like this:
+ --- --- + ---------- + ----------- + | ID | Col1 | Col2 | + ------ + ---------- + ----------- + | 1 | One | X | + ------ + ---------- + ----------- + | 2 | B Y + ------ + ---------- + ----------- + | 3 | C. Jade. + ------ + ---------- + ----------- +
What a way to move columns For example, when I update [3, col1] then data up? The table should look like this ...
+ ------ + ---------- + ----------- + | ID | Col1 | Col2 | + ------ + ---------- + ----------- + | 1 | B X | + ------ + ---------- + ----------- + | 2 | C. Y + ------ + ---------- + ----------- + | 3 | D * | Jade. + ------ + ---------- + ----------- +
* New in line 3, call 1 Value] and column data has been moved; thank you in advanced.
You can do this update
/ join
:
update table t left table tnext on t.id = tnext.id - 1 set t.col1 = (case 'tnext.col1 end when tnext.id is zero) ;
Comments
Post a Comment