[HackerRank MySQL] INNER JOIN 문제풀기 (Basic)

2021. 1. 5. 22:51Today I Learned.../MySQL

Asian Population

Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'.

 

Note: CITY.CountryCode and COUNTRY.Code are matching key columns.

 

Input Format

The CITY and COUNTRY tables are described as follows: 

select sum(city.population)
from city inner join country on city.countrycode = country.code
where continent = 'asia'

African Cities

Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'.

select city.name
from city inner join country on city.countrycode = country.code
where continent = 'africa'

Average Population of Each Continent

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.

select continent, floor(avg(city.population))
from city inner join country on city.countrycode = country.code
group by 1

문제출처: 해커랭크