Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 1, 2020 03:44
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/56692d5d9cdc695eabcd86bb74cc5caa to your computer and use it in GitHub Desktop.
Save codecademydev/56692d5d9cdc695eabcd86bb74cc5caa to your computer and use it in GitHub Desktop.
Codecademy export
WITH oceania AS (
SELECT *
FROM countries
WHERE continent = 'Oceania'
)
SELECT ROUND(SUM(population), 2)
FROM population_years
JOIN oceania
ON oceania.id = population_years.country_id
WHERE year = 2010;
WITH sam AS (
SELECT *
FROM countries
WHERE continent = 'South America'
)
SELECT ROUND(AVG(population), 3)
FROM population_years
JOIN sam
ON sam.id = population_years.country_id
WHERE year = 2010;
SELECT countries.name, population_years.year, MIN(population_years.population) AS 'MinPop'
FROM population_years
JOIN countries
ON countries.id = population_years.country_id
WHERE year = 2007;
WITH average_list AS (
SELECT country_id, ROUND(AVG(population_years.population), 3) AS 'AvgPop'
FROM population_years
GROUP BY country_id
)
SELECT *
FROM average_list
JOIN countries
ON countries.id = average_list.country_id
WHERE countries.name = 'Poland';
SELECT COUNT(*)
FROM countries
WHERE name LIKE '%The%';
SELECT countries.continent, ROUND(SUM(population_years.population), 2) AS 'TotPop'
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