Average Population of Each Continent

  • + 6 comments

    We only need 2 columns in the result set,i.e., continent and average population. Remove city.name from your query.

    You have used round which is correct, but this problem demands us to round the value down to the nearest integer. So, you will have to use either floor() or subtract 0.5 from the avg value and apply round on it(this would go the base integer instead of moving to next one if the decimal part of avg happend to be >=0.5). I used below queries-

    select c.continent,floor(avg(ci.population)) as 'avg_population'
    from city ci
    inner join country c
    ON ci.countrycode = c.code
    group by c.continent;
    

    OR

    select c.continent,round(avg(ci.population)-0.5) as 'avg_population'
    from city ci
    inner join country c
    ON ci.countrycode = c.code
    group by c.continent;