Database

해커랭크 SQL문제_1218

starlikedh 2021. 12. 18. 16:54

Average Population of Each Continent

문제: 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.
CITY.CountryCode and COUNTRY.Code are matching key columns.

풀이: PK, FK인 CountryCode랑 Code 가지고 Continent별 Population을 구하되,

평균을 구하고 rounded down 시키기!

평균은 AVG 사용해서 rounded down은 FLOOR를 사용해서 해결할 수 있었고,

CountryCode랑 Code 가지고 조인 사용해서 데이터 가져오면 문제풀이는 끝이다.