Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 25, 2020 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/ee4313979b88a6493df33a1bc2caaa12 to your computer and use it in GitHub Desktop.
Save codecademydev/ee4313979b88a6493df33a1bc2caaa12 to your computer and use it in GitHub Desktop.
Codecademy export
SELECT COUNT(*) AS 'Number of African Countries'
FROM countries
WHERE continent = 'Africa'
;
SELECT SUM(population) AS 'Population of Oceania in 2005'
FROM countries
JOIN population_years
ON countries.id = population_years.country_id
WHERE continent = 'Oceania' AND
year = 2005
;
SELECT ROUND(AVG(population),2) AS 'Average population of South America in 2003'
FROM countries
JOIN population_years
ON countries.id = population_years.country_id
WHERE continent = 'South America' AND
year = 2003
;
SELECT countries.name AS 'Least Populated country in 2007'
FROM countries
JOIN population_years
ON countries.id = population_years.country_id
WHERE year = 2007
ORDER BY population_years.population
LIMIT 1
;
SELECT ROUND(AVG(population),2) AS 'Average population of Poland over the years'
FROM countries
JOIN population_years
ON countries.id = population_years.country_id
WHERE countries.name = 'Poland'
;
SELECT COUNT(*) AS 'Countries with THE in their name'
FROM countries
WHERE name LIKE '%The%'
;
SELECT countries.continent, SUM(population) AS 'Population of Each Continent'
FROM countries
JOIN population_years
ON countries.id = population_years.country_id
WHERE year = 2010
GROUP BY countries.continent
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment