2013-07-28 42 views
0

我使用的错误行下面的SELECT来获取所有从NFL 2012年冲的戏剧通过发挥数据库发挥SQL选择与REGEXP返回数据

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 
[email protected] 2010 NO (13:36) R.Bush left end pushed ob at MIN 29 for 8 yards (M.Williams A.Allen). 1 2 37 
[email protected] 2010 MIN (12:56) A.Peterson right tackle to MIN 23 for 3 yards (R.Harper). 1 1 80 
[email protected] 2010 MIN (12:16) A.Peterson right tackle to MIN 28 for 5 yards (J.Vilma). 1 2 77 
[email protected] 2010 MIN (11:38) A.Peterson left guard to MIN 27 for -1 yards (S.Shanle J.Dunbar). 1 3 72 
[email protected] 2010 MIN (8:38) A.Peterson left tackle to MIN 41 for 2 yards (J.Vilma S.Shanle). 1 3 61 
[email protected] 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年)和/或团队来过滤?

在此先感谢。

回答

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 
) 
+0

也做到了。谢谢! – NeilG

+0

我可以在你的配置文件中看到你现在没有在Stack Voerflow上使用一个很好的功能。您可以通过点击答案分数下的复选标记,将每个问题的答案标记为解答。也许你想重温一下你以前的问题。而且,每个接受都会得到2个代表点。 –