Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 13, 2020 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/b29813af4167df6612d70fb718ac7d2b to your computer and use it in GitHub Desktop.
Save codecademydev/b29813af4167df6612d70fb718ac7d2b to your computer and use it in GitHub Desktop.
Codecademy export
SELECT COUNT(*) AS '# Countries in Africa'
FROM countries
WHERE continent = 'Africa';
SELECT SUM(population) AS 'Total Population in Oceania in 2005 (mil)'
FROM population_years
JOIN countries
ON countries.id = population_years.country_id
WHERE countries.continent = 'Oceania' AND population_years.year = 2005;
SELECT AVG(population) AS 'Average Population in South America in 2003 (mil)'
FROM population_years
JOIN countries
ON countries.id = population_years.country_id
WHERE countries.continent = 'South America' AND population_years.year = 2003;
SELECT name AS 'Smallest Population in 2007', MIN(population_years.population) AS 'Population(mil)'
FROM countries
JOIN population_years
ON countries.id = population_years.country_id
WHERE population_years.year = 2007;
SELECT AVG(population_years.population) AS 'Average Population Poland (all years, mil)'
FROM population_years
JOIN countries
ON countries.id = population_years.country_id
WHERE countries.name = 'Poland';
SELECT COUNT(*) AS 'Number of countries with The in name'
FROM countries
WHERE name LIKE '%The%';
SELECT countries.continent, SUM(population_years.population) AS 'Population in 2010 (mil)'
FROM population_years
JOIN countries
ON countries.id = population_years.country_id
WHERE population_years.year = 2010
GROUP BY countries.continent
ORDER BY population_years.population;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment