HackerRank-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:

Solution

SELECT SUM(CI.POPULATION)
FROM CITY AS CI
JOIN COUNTRY AS CO ON CI.COUNTRYCODE = CO.CODE
WHERE CONTINENT = ‘Asia’

Surprisingly, when I used COUNTRY.CONTINENT or CI.CONTINENT in where clause I got an error saying that it doesn’t have CONTINENT in the COUNTRY database. So, we should not always be perfect to get results that match others’ expectations 🤣😂😁😊😜.

Thanks a lot for reading. Happy Learning.

--

--

No responses yet