2

所以,我得到了一个users带有字段名country和字段名的表名id

我还有一个Players带有字段名的表名gameID (它也有一个user_idfor id the user id on users

我想对表中的字段进行UPDATE更改gameIDPlayersSTEAMID_0xxxxSTEAMID_1xxxxxcountryusers is = uk

我尝试这样的事情:

UPDATE Players 
set steamid=steam_1 
WHERE steamid=steamid_0 AND country = ( SELECT country 
                                        from users 
                                        where country=pt )

所以我的第一个疑问是,如何只更改单词的一部分(例如:)steam_0:1:2345 to steam_1:1:2345Steam_0* ?也是,我如何选择国家?我的理论看起来很愚蠢:|

我知道那是错误的,也许你可以指出我正确的方向

先感谢您

4

1 回答 1

1

你需要JOIN反对users才能获得国家:

要交换steam_0steam_1您可以使用REPLACE()字符串函数:

UPDATE 
  Players
  JOIN users ON Players.user_id = users.id
SET
  /* REPLACE() the beginnging steamid_0 with steamid_1 */
  steamid = REPLACE(steamid, 'steamid_0:', 'steamid_1:')
WHERE
  /* The whole subquery can then be replaced with this: */
  users.country = 'pt'
  /* Not strictly necessary... */
  AND LEFT(steamid, 10) = 'steamid_0:'
于 2013-01-04T03:53:40.293 回答