We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Average Population of Each Continent
Average Population of Each Continent
Sort by
recency
|
1803 Discussions
|
Please Login in order to post a comment
My solution used LEFT JOIN with COUNTRY as the left table and COALESCE to handle NULLs, so it actually included all continents as the problem stated. The accepted INNER JOIN solution only shows 5 out of 7 continents, which doesn’t seem like 'all' continents to me.
SELECT B.CONTINENT,FLOOR(AVG(A.POPULATION)) AS PROMEDIO FROM CITY A INNER JOIN COUNTRY B ON A.COUNTRYCODE = B.CODE GROUP BY B.CONTINENT ORDER BY PROMEDIO DESC;
MS Sql -
select c.continent , round(avg(ci.population),2) from country c inner join city ci on c.code = ci.countrycode group by c.continent;
For MySQL Platform
The given answer is wrong. Actually we need to use the ROUND function since it's mentioned to round down to nearest integer. I used FLOOR function just to match the answer
MY SQL SELECT COUNTRY.Continent, FLOOR(AVG(CITY.Population)) FROM CITY JOIN COUNTRY ON CITY.CountryCode = COUNTRY.Code GROUP BY COUNTRY.Continent;