CodingSpace

[HackerRank/SQL] Basic Join - Average Population of Each Continent 본문

HackerRank/SQL

[HackerRank/SQL] Basic Join - Average Population of Each Continent

개발자_조이킴 2022. 6. 8. 23:45

Problem. Basic Join - Average Population of Each Continent


Link.

https://www.hackerrank.com/challenges/average-population-of-each-continent/problem?utm_campaign=challenge-recommendation&utm_medium=email&utm_source=7-day-campaign 

 

Average Population of Each Continent | HackerRank

Query the names of all continents and their respective city populations, rounded down to the nearest integer.

www.hackerrank.com


Description.

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.

 

CITY, COUNTRY 테이블을 사용하여 모든 CONTINENT의 이름과 CONTINENT 별 평균인구를 조회하는 쿼리문을 작성하시오.

※ 단, 평균인구 소숫점은 버림(rounded down) 처리하시오.

 

CITY 테이블
COUNTRY 테이블


Key Point. 

AVG,

 

FLOOR,

 

JOIN,

 

GROUP BY,


My Answer. 

SELECT C.CONTINENT, FLOOR(AVG(CI.POPULATION))
FROM CITY CI
    JOIN COUNTRY C
    ON CI.COUNTRYCODE = C.CODE
GROUP BY C.CONTINENT

References. 

 

Comments