Difference between revisions of "SUM and COUNT Quiz"
From SQLZOO
| (12 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | + | SUM and COUNT 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 colspan='5'>...</td> | ||
| + | </tr> | ||
| + | </table> | ||
| + | </div> | ||
<quiz shuffle=none display=simple> | <quiz shuffle=none display=simple> | ||
{Select the statement that shows the sum of population of all countries in 'Europe' | {Select the statement that shows the sum of population of all countries in 'Europe' | ||
| Line 24: | Line 67: | ||
- AVG(), COUNT(), MAX(), MIN(), SUM() | - AVG(), COUNT(), MAX(), MIN(), SUM() | ||
- COUNT(), SUM() | - COUNT(), SUM() | ||
| + | |||
| + | {Select the result that would be obtained from the following code:SELECT region, SUM(area) FROM bbc WHERE SUM(area) > 15000000 GROUP BY region | ||
| + | <table style='float:left'><caption>Table-A</caption><tr><td>Europe</td><td>17000000</td></tr></table> | ||
| + | <table style='float:left'><caption>Table-B</caption><tr><td>Europe</td><td>17000000</td></tr><tr><td>Asia-Pacific</td><td>23460000</td></tr><tr><td>North America</td><td>21660000</td></tr></table> | ||
| + | <table style='float:left'><caption>Table-C</caption><tr><td>Europe</td></tr><tr><td>Asia-Pacific</td></tr><tr><td>North America</td></tr></table> | ||
| + | |type="()"} | ||
| + | - Table-A | ||
| + | - Table-B | ||
| + | - Table-C | ||
| + | - No result due to invalid use of the GROUP BY function | ||
| + | + No result due to invalid use of the WHERE function | ||
{Select the statement that shows the average population of 'Poland', 'Germany' and 'Denmark' | {Select the statement that shows the average population of 'Poland', 'Germany' and 'Denmark' | ||
| Line 33: | Line 87: | ||
- SELECT population FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark') | - SELECT population FROM bbc WHERE name IN ('Poland', 'Germany', 'Denmark') | ||
| − | {Select | + | {Select the statement that shows the medium population density of each region |
|type="()"} | |type="()"} | ||
| − | - | + | - SELECT region, AVG(population/area) AS density FROM bbc |
| − | - SELECT | + | - SELECT region, COUNT(population)/COUNT(area) AS density FROM bbc GROUP BY region |
| − | + | - SELECT region, SUM(population)/COUNT(area) AS density FROM bbc GROUP BY region | |
| − | + SELECT name FROM bbc WHERE region = ' | + | - SELECT region, SUM(population)/SUM(area) AS density FROM bbc HAVING region |
| − | - | + | + SELECT region, SUM(population)/SUM(area) AS density FROM bbc GROUP BY region |
| + | |||
| + | {Select the statement that shows the name and population density of the country with the largest population | ||
| + | |type="()"} | ||
| + | - SELECT name, density AS population/area FROM bbc WHERE population = MAX(population) | ||
| + | - SELECT name, density AS population/area FROM bbc WHERE population = (SELECT MAX(population) FROM bbc) | ||
| + | - SELECT name, MAX (population) FROM bbc WHERE population / (SELECT area FROM bbc) | ||
| + | + SELECT name, population/area AS density FROM bbc WHERE population = (SELECT MAX(population) FROM bbc) | ||
| + | - SELECT name, population/area AS density FROM bbc WHERE population > (SELECT MAX(population) FROM bbc) | ||
| + | |||
| + | {Pick the result that would be obtained from the following code: SELECT region, SUM(area) FROM bbc GROUP BY region HAVING SUM(area)<= 20000000 | ||
| + | <table style='float:left'><caption>Table-A</caption><tr><td>732240</td></tr><tr><td>13403102</td></tr><tr><td>17740392</td></tr><tr><td>4943771</td></tr></table> | ||
| + | <table style='float:left'><caption>Table-B</caption><tr><td>Africa</td><td>22550927</td></tr><tr><td>Asia-Pacific</td><td>28759578</td></tr><tr><td>Europe</td><td>23866987</td></tr><tr><td>North America</td><td>21660000</td></tr></table> | ||
| + | <table style='float:left'><caption>Table-C</caption><tr><td>Africa</td></tr><tr><td>Asia-Pacific</td></tr><tr><td>Europe</td></tr><tr><td>North America</td></tr></table> | ||
| + | <table style='float:left'><caption>Table-D</caption><tr><td>Americas</td><td>732240</td></tr><tr><td>Middle East</td><td>13403102</td></tr><tr><td>South America</td><td>17740392</td></tr><tr><td>South Asia</td><td>49437710</td></tr></table> | ||
| + | <table style='float:left'><caption>Table-E</caption><tr><td>Americas</td></tr><tr><td>Middle East</td></tr><tr><td>South America</td></tr><tr><td>South Asia</td></tr></table> | ||
| + | |type="()"} | ||
| + | - Table-A | ||
| + | - Table-B | ||
| + | - Table-C | ||
| + | + Table-D | ||
| + | - Table-E | ||
| + | |||
</quiz> | </quiz> | ||
[[Category:Quizzes]] | [[Category:Quizzes]] | ||
Revision as of 20:22, 19 September 2012
SUM and COUNT QUIZ
| 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 | |
| ... | ||||