【问题标题】:Conditional Update in SQL with if or case使用 if 或 case 在 SQL 中进行条件更新
【发布时间】:2018-01-10 16:31:12
【问题描述】:

我的问题是是否有办法进行条件更新,例如

if existence = true 
    then update market set exitdate = now(), existence = false
    else then update market set exitdate = null, existence = true

对于我要查找的更多内容,我找不到与我的代码类似的内容。

【问题讨论】:

标签: c# sql postgresql-10


【解决方案1】:

我用下一个代码解决了它...

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
;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-19
    • 1970-01-01
    • 2019-09-02
    • 2023-03-08
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多