我想更新表中具有相同值的多个列。例如,如果我们考虑这张表。
col1 col2
--------------
2 -99
-99 5
3 6
4 -99
Run Code Online (Sandbox Code Playgroud)
我想将表中的 -99 值更新为 NULL,预期结果如下所示。
col1 col2
--------------
2 NULL
NULL 5
3 6
4 NULL
Run Code Online (Sandbox Code Playgroud)
我正在使用这种方式。
update table_name set col1 = null where col1 = -99;
update table_name set col2 = null where col2 = -99;
Run Code Online (Sandbox Code Playgroud)
或者如果我想根据独特的条件更新列该怎么办?例如,第 1 列中为空的 -99 和第 2 列中为空的 5。
有没有办法通过一条语句来实现这一目标?提前致谢。