Difference between revisions of "JOIN Quiz"

From SQLZOO
Jump to: navigation, search
(Created page with "JOIN quiz <quiz shuffle=none display=simple> {Which of following would show all the previous men's singles table tennis gold medalists? |type="()"} - SELECT country.name, colo...")
 
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
JOIN quiz
 
JOIN quiz
 +
<div class="ref_section">
 +
<table class='db_ref'>
 +
<caption>game</caption>
 +
<tr>
 +
<th>id</th>
 +
<th>mdate</th>
 +
<th>stadium</th>
 +
<th>team1</th>
 +
<th>team2</th>
 +
</tr>
 +
<tr>
 +
<td>1001</td>
 +
<td>8 June 2012</td>
 +
<td>National Stadium, Warsaw</td>
 +
<td>POL</td>
 +
<td>GRE</td>
 +
</tr>
 +
<tr>
 +
<td>1002</td>
 +
<td>8 June 2012</td>
 +
<td>Stadion Miejski (Wroclaw)</td>
 +
<td>RUS</td>
 +
<td>CZE</td>
 +
</tr>
 +
<tr>
 +
<td>1003</td>
 +
<td>12 June 2012</td>
 +
<td>Stadion Miejski (Wroclaw)</td>
 +
<td>GRE</td>
 +
<td>CZE</td>
 +
</tr>
 +
<tr>
 +
<td>1004</td>
 +
<td>12 June 2012</td>
 +
<td>National Stadium, Warsaw</td>
 +
<td>POL</td>
 +
<td>RUS</td>
 +
</tr>
 +
<tr>
 +
<td colspan='5'>...</td>
 +
</tr>
 +
</table>
 +
 +
<table class='db_ref'>
 +
<caption>goal</caption>
 +
<tr>
 +
<th>matchid</th>
 +
<th>teamid</th>
 +
<th>player</th>
 +
<th>gtime</th>
 +
</tr>
 +
<tr>
 +
<td>1001</td>
 +
<td>POL</td>
 +
<td>Robert Lewandowski</td>
 +
<td>17</td>
 +
</tr>
 +
<tr>
 +
<td>1001</td>
 +
<td>GRE</td>
 +
<td>Dimitris Salpingidis</td>
 +
<td>51</td>
 +
</tr>
 +
<tr>
 +
<td>1002</td>
 +
<td>RUS</td>
 +
<td>Alan Dzagoev</td>
 +
<td>15</td>
 +
</tr>
 +
<tr>
 +
<td>1001</td>
 +
<td>RUS</td>
 +
<td>Roman Pavlyuchenko</td>
 +
<td>82</td>
 +
</tr>
 +
<tr>
 +
<td colspan='5'>...</td>
 +
</tr>
 +
</table>
 +
 +
<table class='db_ref'>
 +
<caption>eteam</caption>
 +
<tr>
 +
<th>id</th>
 +
<th>teamname</th>
 +
<th>coach</th>
 +
</tr>
 +
<tr>
 +
<td>POL</td>
 +
<td>Poland</td>
 +
<td>Franciszek Smuda</td>
 +
</tr>
 +
<tr>
 +
<td>RUS</td>
 +
<td>Russia</td>
 +
<td>Dick Advocaat</td>
 +
</tr>
 +
<tr>
 +
<td>CZE</td>
 +
<td>Czech Republic</td>
 +
<td>Michal Bilek</td>
 +
</tr>
 +
<tr>
 +
<td>GRE</td>
 +
<td>Greece</td>
 +
<td>Fernando Santos</td>
 +
</tr>
 +
<tr>
 +
<td colspan='5'>...</td>
 +
</tr>
 +
</table>
 +
</div>
 
<quiz shuffle=none display=simple>
 
<quiz shuffle=none display=simple>
{Which of following would show all the previous men's singles table tennis gold medalists?
+
{You want to find the stadium where player 'Dimitris Salpingidis' scored. Select the JOIN condition to use:
 
|type="()"}
 
|type="()"}
- SELECT country.name, color FROM ttms JOIN country ON (ttms.country=country.id) WHERE color = 'gold'
+
- <syntaxhighlight lang='sql'> eteam JOIN game ON (id=team1) </syntaxhighlight>
- SELECT who, country.name, color FROM ttms JOIN country (ttms.country=country.id) WHERE color = 'gold'
+
- <syntaxhighlight lang='sql'> eteam JOIN game ON (id=team2) </syntaxhighlight>
+ SELECT who, country.name, color FROM ttms JOIN country ON (ttms.country=country.id) WHERE color = 'gold'
+
- <syntaxhighlight lang='sql'> eteam JOIN goal ON (teamid=id) </syntaxhighlight>
- SELECT who, country.name, color FROM ttms JOIN country ON (ttms.country=country.id) WHERE color = 'silver'
+
+ <syntaxhighlight lang='sql'> game  JOIN goal ON (id=matchid) </syntaxhighlight>
- SELECT who, country.name, color FROM ttms JOIN country WITH (ttms.country=country.id) WHERE color = 'gold'
+
- <syntaxhighlight lang='sql'> game  JOIN goal ON (team1=teamid OR team2=teamid) </syntaxhighlight>
  
{Which of the following shows the chinese woman's singles winners in the Seoul and Barcelona games?
+
{You JOIN the tables '''goal''' and '''eteam''' in an SQL statement. Indicate the list of column names that may be used in the SELECT line:
 
|type="()"}
 
|type="()"}
- SELECT city FROM ttws JOIN games ON (ttws.games=games.yr) WHERE city IN ('Barcelona', 'Seoul') AND ttws.country = 'CHN'
+
- <syntaxhighlight lang='sql'> gtime, mdate, stadium, match.id </syntaxhighlight>
- SELECT who, city FROM ttws JOIN games IN (ttws.games=games.yr) WHERE city IN ('Barcelona', 'Seoul') AND ttws.country = 'CHN'
+
- <syntaxhighlight lang='sql'> mdate, stadium, id </syntaxhighlight>
- SELECT who, city FROM ttws JOIN games ON (ttws.games=games.yr) WHERE city IN ('Barcelona', 'Atlanta') AND ttws.country = 'CHN'
+
+ <syntaxhighlight lang='sql'> matchid, teamid, player, gtime, id, teamname, coach </syntaxhighlight>
+ SELECT who, city FROM ttws JOIN games ON (ttws.games=games.yr) WHERE city IN ('Barcelona', 'Seoul') AND ttws.country = 'CHN'
+
- <syntaxhighlight lang='sql'> matchid, teamid, player, gtime, mdate, stadium, team1 </syntaxhighlight>
- SELECT who, city FROM ttws JOIN games ON (ttws.games=games.yr) WHERE city IN ('Beijing', 'Seoul') AND ttws.country = 'CHN'
+
- <syntaxhighlight lang='sql'> stadium, team1, team2 </syntaxhighlight>
  
 +
{Select the code which shows players, their team and the amount of goals they scored against Greece(GRE).
 +
|type="()"}
 +
+ <syntaxhighlight lang='sql'> SELECT player, COUNT(*), teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "GRE" OR team2 = "GRE") AND teamid != 'GRE' GROUP BY player </syntaxhighlight>
 +
- <syntaxhighlight lang='sql'> SELECT player, COUNT(*), teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "GRE") AND teamid != 'GRE' GROUP BY player </syntaxhighlight>
 +
- <syntaxhighlight lang='sql'> SELECT player, COUNT(*), teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "POL" OR team2 = "POL") AND teamid != 'POL' GROUP BY player </syntaxhighlight>
 +
- <syntaxhighlight lang='sql'> SELECT player, COUNT(*), teamid FROM game JOIN goal WITH matchid = id WHERE (team1 = "GRE" OR team2 = "GRE") AND teamid != 'GRE' GROUP BY player </syntaxhighlight>
 +
- <syntaxhighlight lang='sql'> SELECT player, teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "GRE" OR team2 = "GRE") AND teamid != 'GRE' GROUP BY player </syntaxhighlight>
  
{Which of these shows the korean women's singles winners in order of medal achieved(Ascending order)?
+
{Select the result that would be obtained from this code: SELECT teamid, mdate FROM goal JOIN game on (matchid=id) WHERE mdate = '9 June 2012'
 +
<table style='float:left'><caption>Table-A</caption><tr><td>DEN</td><td>9 June 2012</td></tr><tr><td>GER</td><td>9 June 2012</td></tr></table>
 +
<table style='float:left'><caption>Table-B</caption><tr><td>DEN</td></tr><tr><td>GER</td></tr></table>
 +
<table style='float:left'><caption>Table-C</caption><tr><td>GRE</td><td>12 June 2012</td></tr><tr><td>CZE</td><td>12 June 2012</td></tr><tr><td>POL</td><td>12 June 2012</td></tr><tr><td>RUS</td><td>12 June 2012</td></tr></table>
 +
<table style='float:left'><caption>Table-D</caption><tr><td>GRE</td></tr><tr><td>CZE</td></tr><tr><td>POL</td></tr><tr><td>RUS</td></tr></table>
 +
<table style='float:left'><caption>Table-E</caption><tr><td>POL</td><td>8 June 2012</td></tr><tr><td>GRE</td><td>8 June 2012</td></tr><tr><td>RUS</td><td>8 June 2012</td></tr><tr><td>CZE</td><td>8 June 2012</td></tr></table>
 
|type="()"}
 
|type="()"}
- SELECT ttws.country, city, color FROM ttws JOIN games ON (ttws.games=games.yr) WHERE ttws.country = 'CHN' ORDER BY color ASC
+
+ Table-A
+ SELECT who, ttws.country, city, color FROM ttws JOIN games ON (ttws.games=games.yr) WHERE ttws.country = 'CHN' ORDER BY color ASC
+
- Table-B
- SELECT who, ttws.country, city, color FROM ttws JOIN games ON (ttws.games=games.yr) WHERE ttws.country = 'CHN' ORDER BY country ASC
+
- Table-C
- SELECT who, ttws.country, city, color FROM ttws JOIN games ON (ttws.games=games.yr) WHERE ttws.country = 'CHN' ORDER BY color DESC
+
- Table-D
- SELECT who, ttws.country, city, color FROM ttws JOIN games ON (ttws.games=games.yr) WHERE who = 'CHN' ORDER BY color ASC
+
- Table-E
  
{Which of these shows the gold medalists for the men's doubles from 1992 to 2000?
+
{Select the code which would show the player and their team for those who have scored against Poland(POL) in National Stadium, Warsaw.
 +
 
 +
<caption>Query-A<syntaxhighlight lang='sql'>
 +
  SELECT DISTINCT player, teamid
 +
  FROM game JOIN goal ON matchid = id
 +
  WHERE stadium = 'National Stadium, Warsaw' AND mdate IN
 +
  (SELECT mdate
 +
    FROM game
 +
    WHERE team1 = 'GER' OR team2 = 'GER')
 +
  AND teamid != 'GER' </syntaxhighlight></caption>
 +
<caption>Query-B<syntaxhighlight lang='sql'>
 +
  SELECT DISTINCT player, teamid
 +
  FROM game JOIN goal ON matchid = id
 +
  WHERE stadium = 'National Stadium, Warsaw' AND mdate IN
 +
    (SELECT mdate
 +
      FROM game
 +
    WHERE team1 = 'POL' OR team2 = 'POL')
 +
  AND teamid != 'POL' </syntaxhighlight></caption>
 +
<caption>Query-C<syntaxhighlight lang='sql'>
 +
SELECT DISTINCT player, teamid
 +
  FROM game JOIN goal ON matchid = id
 +
  WHERE stadium = 'National Stadium, Warsaw' AND teamid != 'POL' </syntaxhighlight></caption>
 +
<caption>Query-D<syntaxhighlight lang='sql'>
 +
SELECT DISTINCT player, teamid
 +
  FROM game JOIN goal ON matchid = id
 +
  WHERE stadium = 'Stadion Miejski (Wroclaw)' AND mdate IN
 +
    (SELECT mdate
 +
      FROM game
 +
    WHERE team1 = 'POL' OR team2 = 'POL')
 +
  AND teamid != 'POL' </syntaxhighlight></caption>
 +
<caption>Query-E<syntaxhighlight lang='sql'>
 +
SELECT DISTINCT stadium, mdate
 +
  FROM game JOIN goal ON matchid = id
 +
  WHERE stadium = 'National Stadium, Warsaw' AND mdate IN
 +
    (SELECT mdate
 +
      FROM game
 +
      WHERE team1 = 'POL' OR team2 = 'POL')
 +
  AND teamid != 'POL' </syntaxhighlight></caption>
 
|type="()"}
 
|type="()"}
+ SELECT name, color, games FROM ttmd JOIN team ON team=team.id WHERE color='gold' AND games BETWEEN 1992 and 2000
+
- Query-A
- SELECT name, color, games FROM ttmd JOIN team ON team=team.id WHERE color='gold' AND games BETWEEN 2092 and 3000
+
+ Query-B
- SELECT name, color, games FROM ttmd JOIN team ON team=team.id WHERE color='gold' AND WHERE games BETWEEN 1992 and 2000
+
- Query-C
- SELECT name, color, games FROM ttmd JOIN team ON team=team.id WHERE color='silver' AND games BETWEEN 1992 and 2000
+
- Query-D
- SELECT name, color, games FROM ttmd JOIN team WITH team=team.id WHERE color='gold' AND games BETWEEN 1992 and 2000
+
- Query-E
  
{Which of the following shows the men's doubles chinese gold medalists who have names beginning with w?
+
{Select the code which shows the player, their team and the time they scored, for players who have played in Stadion Miejski (Wroclaw) but not against Italy(ITA).
 
|type="()"}
 
|type="()"}
- SELECT FROM ttmd JOIN team ON team=team.id WHERE country = 'CHN' AND color = 'gold' AND name LIKE 'W%'
+
- <syntaxhighlight lang='sql'> SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'National Stadium, Warsaw' AND (team1 != 'ITA' AND team2 !='ITA') </syntaxhighlight>
- SELECT name, color, country FROM ttmd JOIN team ON team=team.id WHERE country = 'CHN' AND color = 'gold' AND name IN 'W%'
+
- <syntaxhighlight lang='sql'> SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'Stadion Miejski (Wroclaw)' AND (team1 != 'ESP' AND team2 !='ESP') </syntaxhighlight>
- SELECT name, color, country FROM ttmd JOIN team ON team=team.id WHERE country = 'CHN' AND color = 'gold' AND name LIKE '%W'
+
+ <syntaxhighlight lang='sql'> SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'Stadion Miejski (Wroclaw)' AND (team1 != 'ITA' AND team2 !='ITA') </syntaxhighlight>
+ SELECT name, color, country FROM ttmd JOIN team ON team=team.id WHERE country = 'CHN' AND color = 'gold' AND name LIKE 'W%'
+
- <syntaxhighlight lang='sql'> SELECT DISTINCT teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'Stadion Miejski (Wroclaw)' AND (team1 != 'ITA' AND team2 !='ITA') </syntaxhighlight>
- SELECT name, color, country FROM ttmd JOIN team ON team=team.id WHERE country = 'CHN' AND color = 'silver' AND name LIKE 'W%'
+
- <syntaxhighlight lang='sql'> SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE team1 != 'ITA' AND team2 !='ITA' </syntaxhighlight>
 +
 
 +
{Select the result that would be obtained from this code: SELECT teamname, COUNT(*) FROM eteam JOIN goal ON teamid = id GROUP BY teamname HAVING COUNT(*) < 3
 +
<table style='float:left'><caption>Table-A</caption><tr><td>2</td></tr><tr><td>2</td></tr><tr><td>1</td></tr><tr><td>2</td></tr></table>
 +
<table style='float:left'><caption>Table-B</caption><tr><td>Netherlands</td><td>2</td></tr><tr><td>Poland</td><td>2</td></tr><tr><td>Republic of Ireland</td><td>1</td></tr><tr><td>Ukraine</td><td>2</td></tr></table>
 +
<table style='float:left'><caption>Table-C</caption><tr><td>Netherlands</td></tr><tr><td>Poland</td></tr><tr><td>Republic of Ireland</td></tr><tr><td>Ukraine</td></tr></table>
 +
<table style='float:left'><caption>Table-D</caption><tr><td>Poland</td><td>76</td></tr></table>
 +
<table style='float:left'><caption>Table-E</caption><tr><td>Republic of Ireland</td><td>1</td></tr></table>
 +
|type="()"}
 +
- Table-A
 +
+ Table-B
 +
- Table-C
 +
- Table-D
 +
- Table-E
 +
 
 
</quiz>
 
</quiz>
  
 
[[Category:Quizzes]]
 
[[Category:Quizzes]]

Latest revision as of 11:47, 12 July 2013

JOIN quiz

game
id mdate stadium team1 team2
1001 8 June 2012 National Stadium, Warsaw POL GRE
1002 8 June 2012 Stadion Miejski (Wroclaw) RUS CZE
1003 12 June 2012 Stadion Miejski (Wroclaw) GRE CZE
1004 12 June 2012 National Stadium, Warsaw POL RUS
...
goal
matchid teamid player gtime
1001 POL Robert Lewandowski 17
1001 GRE Dimitris Salpingidis 51
1002 RUS Alan Dzagoev 15
1001 RUS Roman Pavlyuchenko 82
...
eteam
id teamname coach
POL Poland Franciszek Smuda
RUS Russia Dick Advocaat
CZE Czech Republic Michal Bilek
GRE Greece Fernando Santos
...

1. You want to find the stadium where player 'Dimitris Salpingidis' scored. Select the JOIN condition to use:

 eteam JOIN game ON (id=team1)
 eteam JOIN game ON (id=team2)
 eteam JOIN goal ON (teamid=id)
 game  JOIN goal ON (id=matchid)
 game  JOIN goal ON (team1=teamid OR team2=teamid)

2. You JOIN the tables goal and eteam in an SQL statement. Indicate the list of column names that may be used in the SELECT line:

 gtime, mdate, stadium, MATCH.id
 mdate, stadium, id
 matchid, teamid, player, gtime, id, teamname, coach
 matchid, teamid, player, gtime, mdate, stadium, team1
 stadium, team1, team2

3. Select the code which shows players, their team and the amount of goals they scored against Greece(GRE).

 SELECT player, COUNT(*), teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "GRE" OR team2 = "GRE") AND teamid != 'GRE' GROUP BY player
 SELECT player, COUNT(*), teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "GRE") AND teamid != 'GRE' GROUP BY player
 SELECT player, COUNT(*), teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "POL" OR team2 = "POL") AND teamid != 'POL' GROUP BY player
 SELECT player, COUNT(*), teamid FROM game JOIN goal WITH matchid = id WHERE (team1 = "GRE" OR team2 = "GRE") AND teamid != 'GRE' GROUP BY player
 SELECT player, teamid FROM game JOIN goal ON matchid = id WHERE (team1 = "GRE" OR team2 = "GRE") AND teamid != 'GRE' GROUP BY player

4. Select the result that would be obtained from this code: SELECT teamid, mdate FROM goal JOIN game on (matchid=id) WHERE mdate = '9 June 2012'

Table-A
DEN9 June 2012
GER9 June 2012
Table-B
DEN
GER
Table-C
GRE12 June 2012
CZE12 June 2012
POL12 June 2012
RUS12 June 2012
Table-D
GRE
CZE
POL
RUS
Table-E
POL8 June 2012
GRE8 June 2012
RUS8 June 2012
CZE8 June 2012
Table-A
Table-B
Table-C
Table-D
Table-E

5. Select the code which would show the player and their team for those who have scored against Poland(POL) in National Stadium, Warsaw.

Query-A
 
  SELECT DISTINCT player, teamid 
  FROM game JOIN goal ON matchid = id 
  WHERE stadium = 'National Stadium, Warsaw' AND mdate IN 
   (SELECT mdate 
     FROM game 
    WHERE team1 = 'GER' OR team2 = 'GER') 
   AND teamid != 'GER'
Query-B
  SELECT DISTINCT player, teamid 
   FROM game JOIN goal ON matchid = id 
  WHERE stadium = 'National Stadium, Warsaw' AND mdate IN 
    (SELECT mdate 
      FROM game 
     WHERE team1 = 'POL' OR team2 = 'POL')
   AND teamid != 'POL'
Query-C
 
 SELECT DISTINCT player, teamid 
   FROM game JOIN goal ON matchid = id 
  WHERE stadium = 'National Stadium, Warsaw' AND teamid != 'POL'
Query-D
 
 SELECT DISTINCT player, teamid 
   FROM game JOIN goal ON matchid = id 
  WHERE stadium = 'Stadion Miejski (Wroclaw)' AND mdate IN 
    (SELECT mdate 
      FROM game 
     WHERE team1 = 'POL' OR team2 = 'POL')
  AND teamid != 'POL'
Query-E
 
 SELECT DISTINCT stadium, mdate 
   FROM game JOIN goal ON matchid = id 
  WHERE stadium = 'National Stadium, Warsaw' AND mdate IN 
    (SELECT mdate 
       FROM game 
      WHERE team1 = 'POL' OR team2 = 'POL')
  AND teamid != 'POL'
Query-A
Query-B
Query-C
Query-D
Query-E

6. Select the code which shows the player, their team and the time they scored, for players who have played in Stadion Miejski (Wroclaw) but not against Italy(ITA).

 SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'National Stadium, Warsaw' AND (team1 != 'ITA' AND team2 !='ITA')
 SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'Stadion Miejski (Wroclaw)' AND (team1 != 'ESP' AND team2 !='ESP')
 SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'Stadion Miejski (Wroclaw)' AND (team1 != 'ITA' AND team2 !='ITA')
 SELECT DISTINCT teamid, gtime FROM game JOIN goal ON matchid = id WHERE stadium = 'Stadion Miejski (Wroclaw)' AND (team1 != 'ITA' AND team2 !='ITA')
 SELECT DISTINCT player, teamid, gtime FROM game JOIN goal ON matchid = id WHERE team1 != 'ITA' AND team2 !='ITA'

7. Select the result that would be obtained from this code: SELECT teamname, COUNT(*) FROM eteam JOIN goal ON teamid = id GROUP BY teamname HAVING COUNT(*) < 3

Table-A
2
2
1
2
Table-B
Netherlands2
Poland2
Republic of Ireland1
Ukraine2
Table-C
Netherlands
Poland
Republic of Ireland
Ukraine
Table-D
Poland76
Table-E
Republic of Ireland1
Table-A
Table-B
Table-C
Table-D
Table-E

Your score is 0 / 0
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense