mysql - 仅当文本值等于特定文本时如何更新?

标签 mysql sql sql-update where-clause

仅当行的参数 status 等于 'CREATED''NEWSTATUS' 时,我才需要更新该行。我试图用下面的代码来做到这一点,但它仍然是错误的。

UPDATE table t
SET t.otherId, t.status =
    CASE 
        WHEN (SELECT t.status FROM table t WHERE t.idRow) = 'CREATED' THEN '10', 'NEWSTATUS'
    END
WHERE t.idRow = 23

我应该做什么?

最佳答案

您只是在寻找...:

UPDATE table SET otherId = 10, status = 'NEWSTATUS' WHERE idRow = 23 AND status = 'CREATED'

关于mysql - 仅当文本值等于特定文本时如何更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55544427/

相关文章:

php - Laravel 4/PHP : Dynamic where clauses if a variable is not null

php - CakePHP 1.3 和 Ubuntu 16.04

MySQL存储过程调试

sql - 我怎样才能加快这段代码的速度?

sql - Redshift : Table is deleted from the DB with in 5 minutes automatically

postgresql - 在 JSONB 数组中插入元素 - Postgresql

php - 按级别统计结果

mysql - 获取子查询 where 子句 id 与主查询中的 id 匹配

mysql - 使用子查询和连接表更新临时表失败

c# - 如何使用参数从 Access 数据库中保存数字?