Programming/MySQL

[MySQL/Hackerrank] Population Census, African Cities, Average Population of Each Continent

hoojiv 2021. 11. 3. 10:01
728x90

Population Census

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(A.population)
FROM CITY A
    JOIN COUNTRY B
    ON A.CountryCode = B.Code 
WHERE B.CONTINENT = 'Asia';

 

African Cities

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

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

Input Format

The CITY and COUNTRY tables are described as follows:

 

SELECT A.NAME
FROM CITY A
    JOIN COUNTRY B
    ON A.CountryCode = B.Code 
WHERE B.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.

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

Input Format

The CITY and COUNTRY tables are described as follows:

SELECT B.Continent, TRUNCATE(AVG(A.Population),0)
FROM CITY A
    JOIN COUNTRY B
    ON A.CountryCode = B.CODE
GROUP BY B.Continent

 

 

 

728x90
LIST