문제
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의 인구 평균 값은 버림을 해서 정수만 남겨라
출처
반응형
'Algorithm > MySQL' 카테고리의 다른 글
[LeetCode] 181. Employees Earning More Than Their Managers (MySQL) (0) | 2021.07.05 |
---|---|
[LeetCode] 183. Customers Who Never Order (MySQL) (0) | 2021.07.05 |
[해커랭크(HackerRank)] Population Census (MySQL) (0) | 2021.07.05 |
[해커랭크(HackerRank)] African Cities (MySQL) (0) | 2021.07.05 |
[LeetCode] Duplicate Emails (MySQL) (0) | 2021.07.05 |