Population Census

AGGREGATION

Question Link

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 table is described as follows:

The COUNTRY table IS described as follows:

-- Method 1) using WHERE
SELECT SUM(CITY.Population)
FROM CITY, COUNTRY
WHERE CITY.CountryCode=COUNTRY.Code
AND COUNTRY.CONTINENT = 'Asia'

-- Method 2) using JOIN
SELECT 
    SUM(c.population)
FROM City c
LEFT JOIN Country cy
ON c.countrycode = cy.code
WHERE cy.continent = 'Asia'

Last updated