[英]Conditional Update in SQL with if or case
My question is if there is a way to do a conditional update for example 我的问题是例如是否有办法进行条件更新
if existence = true
then update market set exitdate = now(), existence = false
else then update market set exitdate = null, existence = true
For more that I look for, I can't find something similar to my code. 对于所需的更多内容,我找不到与我的代码相似的内容。
I resolved it with the next code... 我用下一个代码解决了...
UPDATE market
SET exitdate = CASE WHEN existence = true AND boxnumm = xxxx then now() else null END,
existence = CASE WHEN exitdate <> null AND boxnumm = xxxx then false else true END
WHERE boxnumm = xxxx
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.