我有这张table。我需要得到所有预测值>游戏最小值和所有预测值与相同的id\u游戏,其中至少有一个预测值>游戏最小值。
在本例中:
GAME
ID PLAYER MIN_VALUE
1 John 1.2
2 Paul 1.4
3 Henry 1.6
4 Tom 2.1
PREDICTIONS
ID_GAME HOUSE VALUE
1 house_a 1.5
1 house_b 1
2 house_a 1.2
2 house_b 1.4
2 house_c 1.5
3 house_a 1.5
3 house_b 1.7
3 house_c 1.8
3 house_d 1.9
4 house_b 1.6
4 house_d 1.9
我需要得到这个:
ID_GAME HOUSE PLAYER VALUE MIN_VALUE
1 house_a John 1.5 1.2
1 house_b John 1 1.2
2 house_a Paul 1.2 1.4
2 house_b Paul 1.4 1.4
2 house_c Paul 1.5 1.4
3 house_a Paul 1.5 1.4
3 house_b Henry 1.7 1.6
3 house_c Henry 1.8 1.6
3 house_d Henry 1.9 1.6
我尝试过这个mysql查询,但没有得到很好的结果:
SELECT *
FROM game m
INNER JOIN predictions p1 ON m.id = p1.id_game
INNER JOIN predictions p2 ON m.id = p2.id_game
WHERE p1.value >= m.min_value OR p2.value < m.min_value
AND p1.id_id_game = p2.id_id_game
1条答案
按热度按时间pkwftd7m1#
您可以尝试在“表名匹配”周围放置“backtick”并使用以下查询:
match是mysql中的保留关键字。有关详细信息,请访问:https://dev.mysql.com/doc/refman/5.7/en/keywords.html#idm140118802075536