World Populations II Challenge Project (SQL)

Here’s my solution:

Hi! My answer below.

Here are my answers

SELECT COUNT(*)

FROM countries

WHERE continent LIKE ‘%africa%’;

–56

SELECT countries.continent, SUM(population_years.population)

FROM population_years

JOIN countries

ON population_years.country_id = countries.id

WHERE countries.continent = ‘Oceania’

AND population_years.year = 2005;

–32.66417

SELECT ROUND(AVG(population_years.population), 6)

FROM population_years

JOIN countries

ON population_years.country_id = countries.id

WHERE countries.continent = ‘South America’

AND population_years.year = 2003;

–25.89065

SELECT countries.name AS ‘Country’, MIN(population_years.population) AS ‘Smallest Population’

FROM population_years

JOIN countries

ON population_years.country_id = countries.id

WHERE population_years.year = 2007;

–Niue with 0.00216

SELECT ROUND(AVG(population_years.population), 6) As ‘The average Population of Poland’

FROM population_years

JOIN countries

ON population_years.country_id = countries.id

WHERE countries.name = ‘Poland’;

–38.560679

SELECT DISTINCT COUNT(name)

FROM countries

WHERE name LIKE (’%The%’);

–4

SELECT Countries.continent, SUM(population_years.population)

FROM population_years

JOIN countries

ON population_years.country_id = countries.id

WHERE population_years.year = 2010

GROUP BY countries.continent;

–Africa 1015.47846

–Asia 4133.09148

–Europe 723.06044

–North America 539.79456

–Oceania 34.95696

–South America 396.58235

My Solution:

Tried to use aliases more to help clarify my queries!

Here is my Solution! please someone review my code if i am doing it right if you have any time TIA!!!

Hello everyone!

These are my answers:

And also, thanks for sharing your answers here!

Hi! This is my first time sharing code on here, and I would love any feedback on things that I didn’t do correctly or that I could’ve done in a more efficient way. Thank you!

Hi folks
Above is my project solution code.
Cheers

I also like using the WITH command.

The example solution doesn’t specify which table a variable is coming from (they use “name” rather than “countries.name”. That code still works. I guess the benefit is that the code is shorter to write, but it is not as easy to see from which table values are coming.