Code Problems/SQL_ HackerRank

[HackerRank] Average Population of Each Continent

simbbo_ 2022. 1. 4. 09:07

https://www.hackerrank.com/challenges/average-population-of-each-continent/problem?isFullScreen=true&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen 

 

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

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:

 

 

[My Answer]

SELECT B.CONTINENT, Floor(avg(A.POPULATION))
FROM CITY A
INNER JOIN
COUNTRY B
ON A.COUNTRYCODE = B.CODE
GROUP BY B.CONTINENT