У меня есть таблица 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 Мне нужно обновить 3 вещи:
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 , все будет работать нормально. Но когда команда запускается, оценки обоих пользователей должны быть обновлены. Кто-нибудь может помочь?