1

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

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。

谢谢。

4

1 回答 1

5

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

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

于 2013-06-10T22:50:54.677 回答