본문 바로가기
Algorithm & SQL/SQL

Average Population of Each Continent - BASIC JOIN

by YoonJong 2022. 6. 9.
728x90

제목 그대로 각 지역의 인구 평균을 구하는 문제이다.

avg 평균을 이용해야하며, 

floor를 이용해야 한다 - > 소수점 자리 버림.

 

또한 group by를 이용해서 그룹을 지어줘야한다

-> 문제 : 모든 대륙의 이름(COUNTRY.Continent)각 대륙의 평균 도시 인구(CITY.Population)를 가장 가까운 정수로 내림하여 쿼리합니다.


 

 

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: 

 

정답 :
SELECT Country.Continent, FLOOR(AVG(City.population))
FROM City INNER JOIN Country
ON City.CountryCode = Country.Code
GROUP BY Country.Continent

 

728x90

'Algorithm & SQL > SQL' 카테고리의 다른 글

[solvesql] SQL 문제 풀이  (0) 2023.01.29
SQL 예제  (0) 2022.06.28
African Cities - BASIC JOIN  (0) 2022.06.09
Population Census - BASIC JOIN  (0) 2022.06.09
Weather Observation Station 10  (0) 2022.06.09

댓글