我有一个查询,在仅搜索1个游戏WHERE gameid = 36的数据时工作正常,但是一旦我尝试加入多个游戏gameid = 36 AND gameid = 37,该查询运行正常,但对所有数据返回全0

SELECT
 CONCAT_WS(  '. ', SUBSTR( p.playerfname, 1, 1 ) , p.playerlname ) name,
 COALESCE( goalEvents.goals, 0 ) goals,
 COALESCE( a1.assists, 0 ) + COALESCE( a2.assists, 0 ) assists,
 COALESCE( goalEvents.goals, 0 ) + COALESCE( a1.assists, 0 ) + COALESCE( a2.assists, 0 ) points
FROM players p
 LEFT JOIN (SELECT scorer, COUNT( scorer ) goals FROM goalEvents WHERE gameid = 36 AND gameid = 37GROUP BY scorer) goalEvents ON p.playerid = goalEvents.scorer
 LEFT JOIN (SELECT assist1, COUNT( assist1 ) assists FROM goalEvents WHERE gameid = 36 AND gameid = 37 GROUP BY assist1) a1 ON p.playerid = a1.assist1
 LEFT JOIN (SELECT assist2, COUNT( assist2 ) assists FROM goalEvents WHERE gameid = 36 AND gameid = 37 GROUP BY assist2) a2 ON p.playerid = a2.assist2
WHERE p.playerteam = 26 ORDER BY points DESC, goals DESC


调用多个游戏行时必定会发生错误

FROM goalEvents WHERE gameid = 36 AND gameid = 37


我通过多个游戏搜索错了吗?我基本上是想按桌子上的最后4个游戏角色进行搜索

最佳答案

尝试:

FROM goalEvents WHERE gameid = 36 OR gameid = 37


您将需要使用OR而不是AND,gameid永远不能是36 AND37。您想找到两个不同的记录,一个记录使用gameid=36,另一个记录使用gameid=37。如果使用AND,则它们都将失败。

如果大于2,也可以尝试gameid IN (36, 37, ...),它是OROROR等的简写

10-04 15:50