如何在一个查询中进行2次更新,查询如下:
UPDATE `stats` SET `coin` = coin + 500 WHERE `player` = 'userone'
UPDATE `stats` SET `coin` = coin - 500 WHERE `player` = 'usertwo'
答案 0 :(得分:1)
您可以使用case
和in
:
UPDATE `stats`
SET `coin` = coin + (case when player = 'userone' then 500 else -500 end)
WHERE `player` in ( 'userone', 'usertwo');
答案 1 :(得分:1)
UPDATE stats
SET coin = CASE player
WHEN 'userone' THEN coin + 500
WHEN 'usertwo' THEN coin - 500
END
WHERE player IN ('userone', 'usertwo')