Average Population of Each Continent

  • + 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;