使用CASE MySQL时出错

Wil*_*ill 1 mysql

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

UPDATE `company_playtime` 
SET front_player_count = CASE 
    WHEN (front_paid + 1) > front_player_count THEN (front_paid + 1) 
    ELSE front_player_count 
END;
Run Code Online (Sandbox Code Playgroud)

此代码给出错误:

错误号码:1054'字段列表'中的未知列'front_player_count'

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

谢谢.

Sim*_*tal 5

Why not try using GREATEST instead? i.e.

UPDATE `company_playtime`
SET front_player_count = GREATEST( front_player_count , front_paid + 1 )
Run Code Online (Sandbox Code Playgroud)

Or better yet, just don't update the unaffected rows

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 
Run Code Online (Sandbox Code Playgroud)

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

This assumes the columns mentioned do exist within company_playtime