gpt4 book ai didi

mysql - 想要编写基于未出现在另一个表中的表中选择的查询

转载 作者:行者123 更新时间:2023-11-29 14:56:37 25 4
gpt4 key购买 nike

我有三个表:player(playerId, Name) , game(gameId, gameName) ,和gameResults(gameId, playerId, results)

我想检索 gameResults 中的行哪里gameIdgame 中不存在.

我的查询是:

SELECT DISTINCT 
gameresults.playerId,
gameresults.results
FROM
game,
gameresults,
player
WHERE
gameresults.playerId = player.playerId
AND gameresults.gameId NOT IN (
SELECT game.gameId; FROM game
)

我也尝试过:

SELECT DISTINCT 
gameresults.playerId,
gameresults.results
FROM
game,
gameresults,
player
WHERE
gameresults.playerId = player.playerId
AND gameresults.gameId NOT EXISTS(
SELECT race.raceId, FROM race
)

最佳答案

SELECT DISTINCT gameresults.playerId, gameresults.results, game.gameName
FROM gameresults
LEFT JOIN game ON game.gameId = gameresults.gameId
/ * WHERE gameresults.gameName Is NULL <-- incorrect */
WHERE gameresults.gameId IS NULL;

关于mysql - 想要编写基于未出现在另一个表中的表中选择的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4478706/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com