Average Population of Each Continent

Sort by

recency

|

1803 Discussions

|

  • + 0 comments

    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 CO.CONTINENT, COALESCE(ROUND(AVG(C.POPULATION), 0), 0)
    FROM COUNTRY AS CO
    LEFT JOIN CITY AS C
        ON C.COUNTRYCODE = CO.CODE
    GROUP BY CO.CONTINENT;
    
  • + 0 comments

    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;

  • + 0 comments

    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;

  • + 0 comments

    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

    SELECT country.continent, FLOOR(AVG(city.population)) FROM country
    JOIN city ON country.code = city.countrycode
    GROUP BY 1;
    
  • + 0 comments

    MY SQL SELECT COUNTRY.Continent, FLOOR(AVG(CITY.Population)) FROM CITY JOIN COUNTRY ON CITY.CountryCode = COUNTRY.Code GROUP BY COUNTRY.Continent;