Simple SQL joins — HackerRank -Average Population of Each Continent

--

Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer.

Note: CITY.CountryCode and COUNTRY.Code are matching key columns.

Input Format

The CITY and COUNTRY tables are described as follows:

Solution

use -0.5 to round to nearest integer.

SELECT continent, 
Round(Avg(city.population) - 0.5, 0) AS p
FROM city
JOIN (country)
ON( city.countrycode = country.code )
GROUP BY continent
ORDER BY p;

--

--

Amber Ivanna Trujillo
Amber Ivanna Trujillo

Written by Amber Ivanna Trujillo

I am Executive Data Science Manager. Interested in Deep Learning, LLM, Startup, AI-Influencer, Technical stuff, Interviews and much more!!!

No responses yet