Practice > SQL > Basic Join > Average Population of Each Continent

Problem

Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer.
Note: CITY.CountryCode and COUNTRY.Code are matching key columns.
문제링크

Answer

SELECT COUNTRY.Continent
     , FLOOR(AVG(CITY.Population)) --  rounded down to the nearest integer
FROM CITY
    INNER JOIN COUNTRY ON CITY.CountryCode = COUNTRY.Code
GROUP BY COUNTRY.Continent -- Continent별로 평균인구수를 구해야 하기 때문에 GROUP BY 해야함.

0개의 댓글