Im between cherry

Hackerrank | MySQL | Average Population of Each Continent 본문

데이터분석/practice_query

Hackerrank | MySQL | Average Population of Each Continent

meal 2020. 8. 29. 16:11

Average Population of Each Continent

Problem

 

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.

 

 

 

SELECT country.continent, FLOOR(AVG(city.population))
FROM city
    LEFT JOIN country ON city.countrycode = country.code
GROUP BY country.continent
HAVING country.continent IS NOT NULL
SELECT COUNTRY.Continent, FLOOR(AVG(CITY.Population))
FROM City
    INNER JOIN Country ON CITY.CountryCode = COUNTRY.Code
GROUP BY COUNTRY.Continent

 

Comments