用户表:

id  |   win  |   lose
0   |   1    |   2
1   |   2    |   8

游戏桌:
id  |  user1  |  user2  |  data
0   |  0      |  1      |  'some text'

数据库是一个简单的多人游戏。我需要一个查询来获取两个用户的user2、data和win-lose数据。这在MySQL中有可能吗?任何帮助都将不胜感激。

最佳答案

你必须像这样把桌子放两次:

SELECT
  u1.win  AS win1,
  u1.lose AS lose1,
  u2.win  AS win2,
  u2.lose AS lose2,
  ...
FROM games g
INNER JOIN users u1 ON g.user1 = u1.id
INNER JOIN users u2 ON g.user2 = u2.id

09-25 17:04