UPDATE `Starcraft2uvsu`
SET IF(`Starcraft2uvsu`.username =  'wasd',  'report1',  'report2' ) =  'Win'
FROM `Starcraft2uvsu`
WHERE `Starcraft2uvsu`.username =  'wasd'


phpmyadmin吐出来的错误是...

#1064 - You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'If(Starcraft2uvsu.username = wasd, 'report1', 'report2') = 'Win' FROM Starcraft2' at line 1


甚至可以通过if语句设置列名吗?我想那是杀手。

神奇的查询是答案和评论的组合。

UPDATE Starcraft2uvsu
SET report1 = CASE WHEN Starcraft2uvsu.username = 'wasd' THEN 'win' ELSE report1 END,
    report2 = CASE WHEN Starcraft2uvsu.username <> 'wasd' THEN 'win' ELSE report2 END
WHERE Starcraft2uvsu.username = 'wasd' OR Starcraft2uvsu.username2 = 'wasd'

最佳答案

是的,没有。您这样做:

set report1 = if (username = 'wasd', 'Win', report1),
    report2 = if (username = 'wasd', report2, 'Win')

关于mysql - MySQL更新错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6825745/

10-09 23:13