如何将以下更新状态减少为一个?
e.g with IF-Clause:
UPDATE users SET registered_at = now() WHERE id = new.id AND status = 'completed';
UPDATE users SET registered_at = NULL WHERE id = new.id AND status != 'completed';
感谢
答案 0 :(得分:1)
使用case
表达式:
UPDATE users
SET registered_at = case when status = 'completed' then now() end
WHERE id = new.id
ELSE NULL
是默认值,因此您无需指定case
表达式的那一部分。