-
-
Save codecademydev/1c5de9f4697f792af44440565901d30d 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
SELECT COUNT(*) AS 'Amount of entries in "countries" table from Africa' | |
FROM countries | |
WHERE continent = 'Africa'; | |
WITH total_population AS ( | |
SELECT * | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
) | |
SELECT continent, SUM(population) AS 'Total population in 2005' | |
FROM total_population | |
WHERE continent = 'Oceania' AND year = 2005; | |
WITH total_population AS ( | |
SELECT * | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
) | |
SELECT continent, AVG(population) AS 'Average population' | |
FROM total_population | |
WHERE continent = 'South America' AND year = 2003; | |
WITH total_population AS ( | |
SELECT * | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
) | |
SELECT continent, MIN(population) AS 'Minimum population' | |
FROM total_population | |
WHERE year = 2007; | |
WITH total_population AS ( | |
SELECT * | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
) | |
SELECT continent, AVG(population) AS 'Average population' | |
FROM total_population | |
WHERE continent = 'Poland'; | |
SELECT COUNT(*) AS 'How many countries have the word "the" in their name' | |
FROM countries | |
WHERE name LIKE '%The%'; | |
WITH total_population AS ( | |
SELECT * | |
FROM countries | |
JOIN population_years | |
ON countries.id = population_years.country_id | |
) | |
SELECT continent, SUM(population) AS 'Total population in 2010' | |
FROM total_population | |
WHERE year = 2010 | |
GROUP BY continent; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment