Last active
May 1, 2020 10:23
-
-
Save MrN00b0t/408020f01ca895e8cf802fccce6c9a3d to your computer and use it in GitHub Desktop.
Codecademy: World Populations II Challenge Project (SQL)
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
SELECT COUNT(*) AS 'No. Of Countries Sampled in Africa' | |
FROM countries | |
WHERE continent = 'Africa'; | |
SELECT ROUND(SUM(population), 2) AS 'Population of Oceania in 2005 (mil)' | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
WHERE countries.continent = 'Oceania' AND population_years.year = 2005; | |
SELECT ROUND(AVG(population), 2) AS 'Average Population of South American Country in 2003 (mil)' | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
WHERE countries.continent = "South America" AND population_years.year = 2003; | |
SELECT name AS 'Country with Smallest Population in 2007' | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
WHERE year = 2007 | |
ORDER BY population ASC | |
LIMIT 1; | |
SELECT ROUND(AVG(population), 2) AS 'Average Population of Poland between 2000 and 2010 inclusive (mil)' | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
WHERE name = 'Poland'; | |
SELECT COUNT(*) AS 'Number of Countries with word "The" in the name (excludes "the" pattern in name)' | |
FROM countries | |
WHERE name LIKE 'The %' OR name LIKE '% The %' OR name LIKE '%The'; | |
SELECT continent AS 'Continent', ROUND(SUM(population), 2) AS 'Total Population in 2010 (mil)' | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
WHERE year = 2010 | |
GROUP BY continent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment