MySQL Query与多个AND运算符

时间:2017-10-04 06:18:08

标签: mysql sql

对不起新手在这里,但我无法让这个查询工作,如果有一个更简单的方法,我会很感激反馈,谢谢。

SELECT players.FirstName, players.LastName, stats.PtsPerGame, 
stats.AstPerGame, stats.RebPerGame, stats.StlPerGame, stats.BlkPerGame 
WHERE stats.PtsPerGame >= 20 
AND stats.AstPerGame >= 3 
AND stats.RebPerGame >= 3 
AND stats.StlPerGame >= 2 
AND stats.BlkPerGame >= 1
From players 
INNER JOIN stats 
ON players.PlayerID = stats.PID 
ORDER BY stats.PtsPerGame DESC;

我收到此错误:

1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在#WHERE stats.PtsPerGame> = 20

附近使用正确的语法

AND stats.AstPerGame> = 3 AND stats.RebPerGame'在第2行

2 个答案:

答案 0 :(得分:0)

条件始终显示在from tablename

之后
SELECT players.FirstName, players.LastName, stats.PtsPerGame, stats.AstPerGame, stats.RebPerGame, stats.StlPerGame, stats.BlkPerGame From players INNER JOIN stats ON players.PlayerID = stats.PID WHERE stats.PtsPerGame >= 20 AND stats.AstPerGame >= 3 AND stats.RebPerGame >= 3 AND stats.StlPerGame >= 2 AND stats.BlkPerGame >= 1 ORDER BY stats.PtsPerGame DESC;

答案 1 :(得分:0)

您需要将WHERE条款降至FROMJOIN

以下

像这样:

SELECT players.FirstName,
       players.LastName,
       stats.PtsPerGame,
       stats.AstPerGame,
       stats.RebPerGame,
       stats.StlPerGame,
       stats.BlkPerGame
FROM players
     INNER JOIN stats ON players.PlayerID = stats.PID
WHERE stats.PtsPerGame >= 20
      AND stats.AstPerGame >= 3
      AND stats.RebPerGame >= 3
      AND stats.StlPerGame >= 2
      AND stats.BlkPerGame >= 1
ORDER BY stats.PtsPerGame DESC;

如果你对这一切都不熟悉,请查看HERE:)