Algorithm/MySQL
[해커랭크(HackerRank)] Average Population of Each Continent (MySQL)
yujin.me
2021. 7. 5. 14:27
문제
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.
코드
SELECT Country.Continent, FLOOR(AVG(City.population))
FROM City INNER JOIN Country
ON City.CountryCode = Country.Code
GROUP BY Country.Continent
- City테이블과 Country테이블 조인
- Continent마다 city의 인구 평균 값을 출력해야하기 때문에 CountryCode를 그룹 바이 해줌
- city의 인구 평균 값은 버림을 해서 정수만 남겨라
출처
반응형