gpt4 book ai didi

mysql - 使用 CASE MySQL 时出错

转载 作者:行者123 更新时间:2023-11-29 04:23:27 25 4
gpt4 key购买 nike

我发现了一些代码并将其修改为新的列名。我检查了几次拼写问题,但无济于事。

UPDATE `company_playtime` 
SET front_player_count = CASE
WHEN (front_paid + 1) > front_player_count THEN (front_paid + 1)
ELSE front_player_count
END;

这段代码报错:

错误编号:1054“字段列表”中的未知列“front_player_count”

如果有帮助的话,我正在使用 codeigniter 和 php。

谢谢。

最佳答案

为什么不尝试使用 GREATEST 呢?即

UPDATE `company_playtime`
SET front_player_count = GREATEST( front_player_count , front_paid + 1 )

或者更好的是,不更新未受影响的行

UPDATE `company_playtime`
SET front_player_count = front_paid + 1
-- use of <= negates requirement for +1 here, should be more efficient
WHERE front_player_count <= front_paid

http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_greatest

这假设提到的列确实存在于 company_playtime

关于mysql - 使用 CASE MySQL 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17034033/

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