SQL中使⽤括号处理and和or
清廉的古诗>有缘来相会
SQLZOO练习–The JOIN operation
咸水鸭的做法
8.The example query shows all goals scored in the Germany-Greece quarterfinal.
Instead show the name of all players who scored a goal against Germany.
HINT
Select goals scored only by non-German players in matches where GER was the id of either team1 or team2.
You can u teamid!=‘GER’ to prevent listing German players.
You can u DISTINCT to stop players being listed twice.
SELECT distinct player
FROM game inner JOIN goal ON id = matchid
WHERE team1 ='GER'OR team2 ='GER'and teamid !='GER'
赫赫有名的近义词运算结果:
player
Dimitris Salpingidis
Georgios Samaras
Marco Reus
Mario Balotelli
Mario Gómez
Mesut Özil
Michael Krohn-Dehli
Miroslav Klo
Philipp Lahm
领结的打法Robin van Persie
Sami Khedira
正确答案:
秋之梦
SELECT distinct player
FROM game inner JOIN goal ON id = matchid
WHERE(team1 ='GER'OR team2 ='GER')and teamid !='GER'锄禾作者
player
Dimitris Salpingidis
查询个人社保缴费明细Georgios Samaras
Mario Balotelli
Michael Krohn-Dehli
Robin van Persie
由于AND的运算符优先于OR运算符,导致程序先运⾏了 team2 = ‘GER’ and teamid != ‘GER’,然后运⾏了 eam1 = ‘GER’ 。要想优先执⾏OR运算符,得使⽤括号()将OR运算符及两侧的查询条件括起来。
AND运算符的优先级⾼于OR运算符。想要优先执⾏OR运算符时,需要使⽤括号。