我想使用这样的静态大小的表:
+------+----------+-----------+
| id | col1 | col2 |
+------+----------+-----------+
| 1 | a | x |
+------+----------+-----------+
| 2 | b | y |
+------+----------+-----------+
| 3 | c | z |
+------+----------+-----------+
例如,当我更新[3,col1]时,有没有办法向上移动列数据?表应如下所示......
+------+----------+-----------+
| id | col1 | col2 |
+------+----------+-----------+
| 1 | b | x |
+------+----------+-----------+
| 2 | c | y |
+------+----------+-----------+
| 3 | d* | z |
+------+----------+-----------+
* [row3,col1]和列数据中的新值已向上移动;提前谢谢。
答案 0 :(得分:1)
您可以使用update
/ join
:
update table t left join
table tnext
on t.id = tnext.id - 1
set t.col1 = (case when tnext.id is null then 'd' else tnext.col1 end);