본문 바로가기
HackerRank - MS SQL Server

[해커랭크/MS SQL] Average Population of Each Continent

by nomeleon 2022. 3. 24.
반응형

문제 링크입니다!

 

Average Population of Each Continent | HackerRank

Query the names of all continents and their respective city populations, rounded down to the nearest integer.

www.hackerrank.com

 

 

문제

 

=> 도시 및 국가 표에 따라 모든 대륙의 이름과 대륙과 각 도시의 평균 인구를 가장 가까운 정수로 내림하여 조회해라.

참고: CITY.CountryCode와 COUNTRY.Code가 일치하는 키 열


 

풀이

SELECT C2.Continent, ROUND(AVG(C1.Population),0)
FROM CITY AS C1
    JOIN COUNTRY AS C2 ON C1.CountryCode = C2.Code 
GROUP BY C2.Continent

 

ROUND(Transact-SQL) - SQL Server

ROUND(Transact-SQL)

docs.microsoft.com

 

 

FLOOR(Transact-SQL) - SQL Server

FLOOR(Transact-SQL)

docs.microsoft.com

 

댓글