-
-
Save codecademydev/ce1c6aede9c4af633c945219d461b1c3 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--How many countries are from Africa | |
SELECT COUNT(*) | |
FROM countries | |
WHERE continent = 'Africa'; | |
--Total population of Oceania in 2005 | |
SELECT SUM(population) FROM population_years | |
INNER JOIN countries ON | |
countries.id = population_years.country_id | |
WHERE year = 2005 | |
AND continent = 'Oceania'; | |
--Average population of countries in S.A in 2003 | |
SELECT AVG(population) FROM population_years | |
INNER JOIN countries ON | |
countries.id = population_years.country_id | |
WHERE year = 2003 | |
AND continent = 'South America'; | |
--Country with smallest population in 2007 | |
SELECT name, year, MIN(population) | |
FROM population_years | |
INNER JOIN countries | |
ON countries.id = population_years.country_id | |
WHERE year = 2007; | |
--Average population of Poland | |
SELECT name, AVG(population) | |
FROM population_years | |
INNER JOIN countries | |
ON countries.id = population_years.country_id | |
WHERE name = 'Poland'; | |
--How many countries have "The" in the name | |
SELECT name | |
FROM countries | |
WHERE name LIKE "%The"; | |
--Total population of each continent in 2010 | |
SELECT continent, SUM(population) | |
FROM population_years | |
INNER JOIN countries | |
ON countries.id = population_years.country_id | |
GROUP BY continent | |
ORDER BY SUM(population); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment