Simple SQL joins — HackerRank -Average Population of Each Continent
Oct 20, 2020
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;