0

我正在使用以下 SELECT 从 NFL 逐个播放数据库中获取所有 2012 年的冲球

Select gameid, season, off, description, qtr, down, ydstogoal 
FROM 2010_12pxp
WHERE DESCRIPTION LIKE "%up the middle%" OR DESCRIPTION REGEXP "(left|right) (tackle|guard|end)" OR DESCRIPTION REGEXP " rushe(d|s) for "
AND season = 2012
GROUP BY id

但是,它会返回数据库中所有正在运行的播放,而不仅仅是 2012 年的播放。示例:

gameid  season  off description qtr down    ydstogoal
20100909_MIN@NO 2010    NO  (13:36) R.Bush left end pushed ob at MIN 29 for 8 yards (M.Williams A.Allen).   1   2   37
20100909_MIN@NO 2010    MIN (12:56) A.Peterson right tackle to MIN 23 for 3 yards (R.Harper).   1   1   80
20100909_MIN@NO 2010    MIN (12:16) A.Peterson right tackle to MIN 28 for 5 yards (J.Vilma).    1   2   77
20100909_MIN@NO 2010    MIN (11:38) A.Peterson left guard to MIN 27 for -1 yards (S.Shanle J.Dunbar).   1   3   72
20100909_MIN@NO 2010    MIN (8:38) A.Peterson left tackle to MIN 41 for 2 yards (J.Vilma S.Shanle). 1   3   61
20100909_MIN@NO 2010    MIN (7:51) A.Peterson right end to NO 42 for 17 yards (R.Gay). PENALTY on MIN-V.Shiancoe Offensive Holding 10 yards enforced at MIN 41 - No Play.   1   2   59

如何让它仅按赛季(2012 年)和/或团队过滤?

提前致谢。

4

1 回答 1

0

使用额外的括号

Select gameid, season, off, description, qtr, down, ydstogoal 
FROM 2010_12pxp
WHERE 
(
   DESCRIPTION LIKE "%up the middle%" 
   OR DESCRIPTION REGEXP "(left|right) (tackle|guard|end)" 
   OR DESCRIPTION REGEXP " rushe(d|s) for "
)
AND season = 2012
GROUP BY id

如果您不这样做,那么您的查询将被解释为这样

WHERE DESCRIPTION LIKE "%up the middle%" 
OR DESCRIPTION REGEXP "(left|right) (tackle|guard|end)" 
OR 
(
   DESCRIPTION REGEXP " rushe(d|s) for "
   AND season = 2012
)
于 2013-07-28T13:42:36.220 回答