gpt4 book ai didi

MySQL Update CASE 用 "0"更新字段

转载 作者:行者123 更新时间:2023-12-01 00:22:22 25 4
gpt4 key购买 nike

我在使用 CASE 语句更新 SQL 表时遇到问题。

SELECT number,amount,minimuminventory FROM artikel WHERE number=17;
+--------+--------+------------------+| number | amount | minimuminventory |+--------+--------+------------------+|     17 |     10 |                0 |+--------+--------+------------------+

I have an amount of 10 but when I update my table:

UPDATE artikel 
SET amount = CASE WHEN amount - minimuminventory - 2 < 0
THEN amount=amount-2
ELSE amount=99
END
WHERE artnr=17;

Query OK, 1 rows affected (0,01 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql 更新我的表,集合数量为 0

SELECT number,amount,minimuminventory FROM artikel WHERE number=17;
+--------+--------+------------------+| number | amount | minimuminventory |+--------+--------+------------------+|     17 |      0 |                0 |+--------+--------+------------------+

你看到问题了吗?

最佳答案

amount = CASE WHEN amount - minimuminventory - 2 < 0 THEN amount=amount-2 ELSE amount=99 END

CASE 语句中的值是 amount 列的预期值,但您在它的 THEN 和 ELSE 部分中再次执行 amount=x。将其更改为:

amount = CASE WHEN amount - minimuminventory - 2 < 0 THEN amount-2 ELSE 99 END

关于MySQL Update CASE 用 "0"更新字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22708639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com