Difference between revisions of "Nested SELECT Quiz"

From SQLZOO
Jump to: navigation, search
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
Nested SELECT quiz
 
Nested SELECT quiz
 +
<div class='ref_section'>
 +
<table class='db_ref'>
 +
<caption>bbc</caption>
 +
<tr>
 +
<th>name</th>
 +
<th>region</th>
 +
<th>area</th>
 +
<th>population</th>
 +
<th>gdp</th>
 +
</tr>
 +
<tr>
 +
<td>Afghanistan</td>
 +
<td>South Asia</td>
 +
<td align='right'>652225</td>
 +
<td align='right'>26000000</td>
 +
<td></td>
 +
</tr>
 +
<tr>
 +
<td>Albania</td>
 +
<td>Europe</td>
 +
<td align='right'>28728</td>
 +
<td align='right'>3200000</td>
 +
<td align='right'>6656000000</td>
 +
</tr>
 +
<tr>
 +
<td>Algeria</td>
 +
<td>Middle East</td>
 +
<td align='right'>2400000</td>
 +
<td align='right'>32900000</td>
 +
<td align='right'>75012000000</td>
 +
</tr>
 +
<tr>
 +
<td>Andorra</td>
 +
<td>Europe</td>
 +
<td align='right'>468</td>
 +
<td align='right'>64000</td>
 +
<td></td>
 +
</tr>
 +
<tr>
 +
<td>Bangladesh</td>
 +
<td>South Asia</td>
 +
<td align='right'>143998</td>
 +
<td align='right'>152600000</td>
 +
<td>67144000000</td>
 +
</tr>
 +
<tr>
 +
<td>United Kingdom</td>
 +
<td>Europe</td>
 +
<td align='right'>242514</td>
 +
<td align='right'>59600000</td>
 +
<td>2022824000000</td>
 +
</tr>
 +
<tr>
 +
<td colspan='5'>...</td>
 +
</tr>
 +
</table>
 +
</div>
 
<quiz shuffle=none display=simple>
 
<quiz shuffle=none display=simple>
 
{Select the code that shows the name, region and population of the smallest country in each region
 
{Select the code that shows the name, region and population of the smallest country in each region
 
|type="()"}
 
|type="()"}
-A. SELECT region, name, FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
+
- <syntaxhighlight lang='sql'> SELECT region, name, FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0) </syntaxhighlight>
-B. SELECT region, name, population FROM bbc WHERE population <= ALL (SELECT population FROM bbc WHERE population>0)
+
- <syntaxhighlight lang='sql'> SELECT region, name, population FROM bbc WHERE population <= ALL (SELECT population FROM bbc WHERE population>0) </syntaxhighlight>
+C. SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
+
+ <syntaxhighlight lang='sql'> SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0) </syntaxhighlight>
-D. SELECT region, name, population FROM bbc x WHERE population = ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
+
- <syntaxhighlight lang='sql'> SELECT region, name, population FROM bbc x WHERE population = ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0) </syntaxhighlight>
-E. SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population<0)
+
- <syntaxhighlight lang='sql'> SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population<0) </syntaxhighlight>
  
 
{Select the code that shows the countries belonging to regions with all populations over 50000
 
{Select the code that shows the countries belonging to regions with all populations over 50000
 
|type="()"}
 
|type="()"}
-A. SELECT name,region,population FROM bbc x WHERE 50000 <= ALL (SELECT population FROM bbc y WHERE population>0)
+
- <syntaxhighlight lang='sql'> SELECT name,region,population FROM bbc x WHERE 50000 <= ALL (SELECT population FROM bbc y WHERE population>0)
+B. SELECT name,region,population FROM bbc x WHERE 50000 <= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
+
+ <syntaxhighlight lang='sql'> SELECT name,region,population FROM bbc x WHERE 50000 <= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0) </syntaxhighlight>
-C. SELECT name,region,population FROM bbc x WHERE 50000 = ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
+
- <syntaxhighlight lang='sql'> SELECT name,region,population FROM bbc x WHERE 50000 = ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0) </syntaxhighlight>
-D. SELECT name,region,population FROM bbc x WHERE 50000 >= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
+
- <syntaxhighlight lang='sql'> SELECT name,region,population FROM bbc x WHERE 50000 >= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0) </syntaxhighlight>
-E. SELECT name,region,population FROM bbc x WHERE 500000 <= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
+
- <syntaxhighlight lang='sql'> SELECT name,region,population FROM bbc x WHERE 500000 <= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0) </syntaxhighlight>
 
+
  
 
{Select the code that shows the countries with a third of the population of the countries around it
 
{Select the code that shows the countries with a third of the population of the countries around it
 
|type="()"}
 
|type="()"}
+A. SELECT name, region FROM bbc x WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
+
+ <syntaxhighlight lang='sql'> SELECT name, region FROM bbc x WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name) </syntaxhighlight>
-B. SELECT name, region FROM bbc x WHERE population = ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
+
- <syntaxhighlight lang='sql'> SELECT name, region FROM bbc x WHERE population = ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name) </syntaxhighlight>
-C. SELECT name, region FROM bbc x WHERE population > ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
+
- <syntaxhighlight lang='sql'> SELECT name, region FROM bbc x WHERE population > ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name) </syntaxhighlight>
-D. SELECT name, region FROM bbc x WHERE population < ALL (SELECT population*3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
+
- <syntaxhighlight lang='sql'> SELECT name, region FROM bbc x WHERE population < ALL (SELECT population*3 FROM bbc y WHERE y.region = x.region AND y.name != x.name) </syntaxhighlight>
-E. SELECT name, region FROM bbc x WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.name != x.name)
+
- <syntaxhighlight lang='sql'> SELECT name, region FROM bbc x WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.name != x.name)
 +
 
 +
{Select the result that would be obtained from the following code:
 +
<source lang=sql>
 +
SELECT name FROM bbc
 +
WHERE population >
 +
      (SELECT population
 +
          FROM bbc
 +
        WHERE name='United Kingdom')
 +
  AND region IN
 +
      (SELECT region
 +
          FROM bbc
 +
        WHERE name = 'United Kingdom')
 +
</source>
 +
<table><caption>Table-A</caption><tr><td>Andorra</td></tr><tr><td>Albania</td></tr><tr><td>Austria</td></tr><tr><td>Bulgaria</td></tr></table>
 +
<table><caption>Table-B</caption><tr><td>France</td><td>Europe</td></tr><tr><td>Germany</td><td>Europe</td></tr><tr><td>Russia</td><td>Europe</td></tr><tr><td>Turkey</td><td>Europe</td></tr></table>
 +
<table><caption>Table-C</caption><tr><td>France</td></tr><tr><td>Germany</td></tr><tr><td>Andorra</td></tr><tr><td>Albania</td></tr></table>
 +
<table><caption>Table-D</caption><tr><td>France</td></tr><tr><td>Germany</td></tr><tr><td>Russia</td></tr><tr><td>Turkey</td></tr></table>
 +
<table><caption>Table-E</caption><tr><td>France</td></tr><tr><td>Germany</td></tr><tr><td>Russia</td></tr><tr><td>Turkey</td></tr><tr><td>Brazil</td></tr><tr><td>United States of USA</td></tr><tr><td>Canada</td></tr></table>
 +
|type="()"}
 +
- Table-A
 +
- Table-B
 +
- Table-C
 +
+ Table-D
 +
- Table-E
  
 
{Select the code that would show the countries with a greater GDP then any country in Africa
 
{Select the code that would show the countries with a greater GDP then any country in Africa
 
|type="()"}
 
|type="()"}
-A. SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND gdp=0)
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND gdp=0) </syntaxhighlight>
+B. SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND gdp IS NOT NULL)
+
+ <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND gdp IS NOT NULL) </syntaxhighlight>
-C. SELECT name FROM bbc WHERE gdp > ALL (SELECT MIN(gdp) FROM bbc WHERE region = 'Africa' AND gdp IS NOT NULL)
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE gdp > ALL (SELECT MIN(gdp) FROM bbc WHERE region = 'Africa' AND gdp IS NOT NULL) </syntaxhighlight>
-D. SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND population IS NOT NULL)
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND population IS NOT NULL) </syntaxhighlight>
-E. SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Europe' AND gdp IS NOT NULL)
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Europe' AND gdp IS NOT NULL) </syntaxhighlight>
  
 
{Select the code that shows the countries with population smaller than Russia but bigger than Denmark
 
{Select the code that shows the countries with population smaller than Russia but bigger than Denmark
 
|type="()"}
 
|type="()"}
-A. SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Denmark') AND population > (SELECT population FROM bbc WHERE name='Russia')
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Denmark') AND population > (SELECT population FROM bbc WHERE name='Russia') </syntaxhighlight>
+B. SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark')
+
+ <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark') </syntaxhighlight>
-C. SELECT name FROM bbc WHERE population = (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark')
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE population = (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark') </syntaxhighlight>
-D. SELECT name FROM bbc WHERE population > (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark')
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE population > (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark') </syntaxhighlight>
-E. SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Russia' AND population > (SELECT population FROM bbc WHERE name='Denmark')
+
- <syntaxhighlight lang='sql'> SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Russia' AND population > (SELECT population FROM bbc WHERE name='Denmark') </syntaxhighlight>
 +
 
 +
{Select the result that would be obtained from the following code: SELECT name FROM bbc WHERE population > ALL (SELECT MAX(population) FROM bbc WHERE region = 'Europe') AND region ='South Asia'
 +
<table><caption>Table-A</caption><tr><td>Afghanistan</td></tr><tr><td>Bhutan</td></tr><tr><td>Nepal</td></tr><tr><td>Sri Lanka</td></tr><tr><td>The Maldives</td></tr></table>
 +
<table><caption>Table-B</caption><tr><td>Bangladesh</td></tr><tr><td>India</td></tr><tr><td>Pakistan</td></tr></table>
 +
<table><caption>Table-C</caption><tr><td>China</td></tr><tr><td>India</td></tr></table>
 +
<table><caption>Table-D</caption><tr><td>Brazil</td></tr><tr><td>Bangladesh</td></tr><tr><td>China</td></tr><tr><td>India</td></tr></table>
 +
<table><caption>Table-E</caption><tr><td>France</td></tr><tr><td>Germany</td></tr><tr><td>Russia</td></tr><tr><td>Trukey</td></tr></table>
 +
|type="()"}
 +
- Table-A
 +
+ Table-B
 +
- Table-C
 +
- Table-D
 +
- Table-E
 
</quiz>
 
</quiz>
  
 
[[Category:Quizzes]]
 
[[Category:Quizzes]]

Revision as of 10:44, 12 July 2013

Nested SELECT quiz

bbc
name region area population gdp
Afghanistan South Asia 652225 26000000
Albania Europe 28728 3200000 6656000000
Algeria Middle East 2400000 32900000 75012000000
Andorra Europe 468 64000
Bangladesh South Asia 143998 152600000 67144000000
United Kingdom Europe 242514 59600000 2022824000000
...

1. Select the code that shows the name, region and population of the smallest country in each region

 SELECT region, name, FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
 SELECT region, name, population FROM bbc WHERE population <= ALL (SELECT population FROM bbc WHERE population>0)
 SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
 SELECT region, name, population FROM bbc x WHERE population = ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population>0)
 SELECT region, name, population FROM bbc x WHERE population <= ALL (SELECT population FROM bbc y WHERE y.region=x.region AND population<0)

2. Select the code that shows the countries belonging to regions with all populations over 50000

 SELECT name,region,population FROM bbc x WHERE 50000 <= ALL (SELECT population FROM bbc y WHERE population>0)
 SELECT name,region,population FROM bbc x WHERE 50000 <= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
 SELECT name,region,population FROM bbc x WHERE 50000 = ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
 SELECT name,region,population FROM bbc x WHERE 50000 >= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)
 SELECT name,region,population FROM bbc x WHERE 500000 <= ALL (SELECT population FROM bbc y WHERE x.region=y.region AND y.population>0)

3. Select the code that shows the countries with a third of the population of the countries around it

 SELECT name, region FROM bbc x WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
 SELECT name, region FROM bbc x WHERE population = ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
 SELECT name, region FROM bbc x WHERE population > ALL (SELECT population/3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
 SELECT name, region FROM bbc x WHERE population < ALL (SELECT population*3 FROM bbc y WHERE y.region = x.region AND y.name != x.name)
 SELECT name, region FROM bbc x WHERE population < ALL (SELECT population/3 FROM bbc y WHERE y.name != x.name)

4. Select the result that would be obtained from the following code:

SELECT name FROM bbc
 WHERE population >
       (SELECT population
          FROM bbc
         WHERE name='United Kingdom')
   AND region IN
       (SELECT region
          FROM bbc
         WHERE name = 'United Kingdom')
Table-A
Andorra
Albania
Austria
Bulgaria
Table-B
FranceEurope
GermanyEurope
RussiaEurope
TurkeyEurope
Table-C
France
Germany
Andorra
Albania
Table-D
France
Germany
Russia
Turkey
Table-E
France
Germany
Russia
Turkey
Brazil
United States of USA
Canada
Table-A
Table-B
Table-C
Table-D
Table-E

5. Select the code that would show the countries with a greater GDP then any country in Africa

 SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND gdp=0)
 SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND gdp IS NOT NULL)
 SELECT name FROM bbc WHERE gdp > ALL (SELECT MIN(gdp) FROM bbc WHERE region = 'Africa' AND gdp IS NOT NULL)
 SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Africa' AND population IS NOT NULL)
 SELECT name FROM bbc WHERE gdp > ALL (SELECT MAX(gdp) FROM bbc WHERE region = 'Europe' AND gdp IS NOT NULL)

6. Select the code that shows the countries with population smaller than Russia but bigger than Denmark

 SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Denmark') AND population > (SELECT population FROM bbc WHERE name='Russia')
 SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark')
 SELECT name FROM bbc WHERE population = (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark')
 SELECT name FROM bbc WHERE population > (SELECT population FROM bbc WHERE name='Russia') AND population > (SELECT population FROM bbc WHERE name='Denmark')
 SELECT name FROM bbc WHERE population < (SELECT population FROM bbc WHERE name='Russia' AND population > (SELECT population FROM bbc WHERE name='Denmark')

7. Select the result that would be obtained from the following code: SELECT name FROM bbc WHERE population > ALL (SELECT MAX(population) FROM bbc WHERE region = 'Europe') AND region ='South Asia'

Table-A
Afghanistan
Bhutan
Nepal
Sri Lanka
The Maldives
Table-B
Bangladesh
India
Pakistan
Table-C
China
India
Table-D
Brazil
Bangladesh
China
India
Table-E
France
Germany
Russia
Trukey
Table-A
Table-B
Table-C
Table-D
Table-E

Your score is 0 / 0
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense