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 해야함.
profile
데이터가 우리를 이롭게 하리라.

0개의 댓글