Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 29, 2020 19:09
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/4eca9bd6608c188491a3e4af39671f0c to your computer and use it in GitHub Desktop.
Save codecademydev/4eca9bd6608c188491a3e4af39671f0c to your computer and use it in GitHub Desktop.
Codecademy export
WITH total AS (
SELECT *
FROM population_years
JOIN countries
ON population_years.country_id = countries.id
)
-- 3
SELECT COUNT(*)
FROM countries
WHERE continent = 'Africa';
-- 4
SELECT SUM(population)
FROM total
WHERE year == 2005
AND continent == 'Oceania';
-- 5
SELECT AVG(population)
FROM total
WHERE year == 2003
AND continent == 'South America';
--6
SELECT name, MIN(population)
FROM total
WHERE year = 2007;
--7
SELECT SUM(population)
FROM total
WHERE name == 'Poland';
--8
SELECT name
FROM total
WHERE name LIKE '%the%'
GROUP BY name;
--9
SELECT continent, SUM(population)
FROM total
WHERE year == 2010
GROUP BY continent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment