sql用其他列中的值替换空值

Gid*_*eon 1 sql

我想用同一行另一列中的值替换所有具有 NULL 值的值。

我尝试了不同的 sql 语句,但没有成功。

问候

Gur*_*ngh 6

如果要更新,请执行以下操作:

update t set col1 = col2
where col1 is null
Run Code Online (Sandbox Code Playgroud)

如果您只想进行选择,请使用大多数数据库支持coalesce

select coalesce(col1, col2) from t;
Run Code Online (Sandbox Code Playgroud)