SQL/HackerRank(해커랭크)

HackerRank(해커랭크) MySQL Average Population of Each Continent 문제 답

진리뷰 2023. 10. 5. 09:00
반응형

HackerRank(해커랭크)-MySQL-Average-Population-of-Each-Continent-문제-답-썸네일
Average Population of Each Continent

 

*MySQL 버전, Basic Join 문제입니다.

 

 

 

해커랭크 Average Population of Each Contient 문제

 

  • 국가 테이블에서 대륙 이름 가져오기
  • 각 도시별 평균 인구수 구하기 이때, 평균값은 정수로 내림 반환.
  • 공통키: CITY.countrycode = COUNTRY.code

 

해커랭크Average Population of Each Continent-문제
Average Population of Each Continent 문제

 

 

중복 컬럼명들이 있으므로 테이블 구분 유의.

해커랭크Average Population of Each Continent-샘플
Average Population of Each Continent 문제 테이블

 

 

 

 

해커랭크 Average Population of Each Continent 답

 

  • FLOOR: 숫자를 가장 큰 정수로 내림한다.
SELECT country.continent
, FLOOR(AVG(city.population))
FROM country, city
WHERE city.countrycode = country.code;
GROUP BY 1;

 

 

 

추가 정리

 

  • GROUP BY 사용 시 SELECT의 집계 함수 외 모두 선언해야 함.
반응형
top