1. 문제
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.
Input Format
The CITY and COUNTRY tables are described as follows:
2. 답
SELECT country.continent, FLOOR(AVG(city.population))
FROM city
INNER JOIN country ON city.countrycode = country.code
GROUP BY country.continent
3. KEY POINT
- INNER JOIN : 양쪽 테이블의 모두 있는 정보를 합침
- AVG(컬럼이름) : 해당 컬럼의 평균
- FLOOR() : 내림
- GROUP BY : 기준을 중심으로 그룹화
hackerrank.com/challenges/average-population-of-each-continent/problem?h_r=internal-search
'MySQL > 문제풀이' 카테고리의 다른 글
[LeetCode] Self JOIN : 181. Employees Earning More Than Their Managers (0) | 2021.03.15 |
---|---|
[LeetCode] LEFT JOIN : 183. Customers Who Never Order (0) | 2021.03.15 |
[HackerRank] INNER JOIN : Asian Population (0) | 2021.03.15 |
[HackerRank] INNER JOIN : African Cities (0) | 2021.03.15 |
[HackerRank] CASE : Type of Triangle (0) | 2021.03.15 |
댓글