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
|
1805 Discussions
|
Please Login in order to post a comment
SELECT co.continent, floor(avg(ci.population)) from country co INNER join city ci on co.code = ci.countrycode group by co.continent;
SELECT country.continent, floor(avg(city.population)) AS avg_population FROM CITY INNER JOIN country ON city.countrycode = country.code GROUP BY country.continent;
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;