我有一个mysql表,用于记录双人比赛,如下所示:
- gameid
- id1 // id of player 1
- id2 // id of player 2
- score1 // score of player 1
- score2 // score of player 2
- state // state of the games is initially 0, then the score updates are made and in order to prevent further updates the state must be updated to 1
我需要检查记录,并根据分数更新另一个“用户”表。前任:
如果
得分1>得分2
我需要更新三件事:
1- the state of the game // from 0 to 1
2- in table "users" add 1 point to the column score for the user with userid = id1
2- in table "users" subtract 1 point from the column score for the user with userid = id2
到目前为止,我可以更新1和2,但我需要在一个命令中完成所有3个更新:
UPDATE dbo.games AS GA , dbo.users AS US
SET GA.state = 1, US.score = US.score + 1
WHERE US.id = GA.id1 AND GA.state = 0 and GA.score1 > GA.score2
我可以分开
1.
和
1.
命令,它会工作得很好。但是,当运行该命令时,两个用户的分数都应该更新。有人能帮忙吗?