Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 23, 2020 18:14
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/2d48511f275a5696677d77c828ec70ed to your computer and use it in GitHub Desktop.
Save codecademydev/2d48511f275a5696677d77c828ec70ed to your computer and use it in GitHub Desktop.
Codecademy export
select count(*) as 'Countries in Africa'
from countries
where continent='Africa';
select round(sum(population),2) as 'Total Pop', round(avg(population),2) as 'Avg Pop', countries.continent, population_years.year
from population_years
left join countries
on population_years.country_id=countries.id
WHERE countries.continent = 'Oceania' and population_years.year = 2005
OR countries.continent = 'South America' and population_years.year = 2003
group by 4
order by 3 desc;
select countries.name as 'Country', min(population) 'Population'
from population_years
join countries
on population_years.country_id=countries.id
where population_years.year = 2007;
select countries.name as 'Country', round(avg(population),2) as 'Avg Pop'
from countries
join population_years
on countries.id=population_years.country_id
where countries.name = 'Poland';
select name
from countries
where name like '%the';
select countries.continent as 'Continent', population_years.population
from countries
left join population_years
on countries.id=population_years.country_id
where population_years.year = 2010
group by 1
order by 2 desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment