Average Population of Each Continent

Sort by

recency

|

1805 Discussions

|

  • + 0 comments

    SELECT co.continent, floor(avg(ci.population)) from country co INNER join city ci on co.code = ci.countrycode group by co.continent;

  • + 0 comments

    SELECT country.continent, floor(avg(city.population)) AS avg_population FROM CITY INNER JOIN country ON city.countrycode = country.code GROUP BY country.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;
    
  • + 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;