Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 23, 2020 09:16
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/1c5de9f4697f792af44440565901d30d to your computer and use it in GitHub Desktop.
Save codecademydev/1c5de9f4697f792af44440565901d30d to your computer and use it in GitHub Desktop.
Codecademy export
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