Putting it all together
Updated Aug 28, 2019 ·
Final challenge
This is the final challenge in the Joining Data in SQL course in Datacamp.
Tables
Below are the tables used for this challenge.
Instructions
Your task is to determine the top 10 capital cities in Europe and the Americas by city_perc, a metric you'll calculate. city_perc is a percentage that calculates the "proper" population in a city as a percentage of the total population in the wider metro area, as follows:
city_proper_pop / metroarea_pop * 100
Note:
- Do not use table aliasing in this exercise.
- From
cities, select the city name, country code, proper population, and metro area population, as well as the fieldcity_perc, which calculates the proper population as a percentage of metro area population for each city (using the formula provided). - Filter city name with a subquery that selects
capitalcities fromcountriesin 'Europe' or continents with 'America' at the end of their name. - Exclude
NULLvalues inmetroarea_pop. - Order by
city_perc(descending) and return only the first 10 rows.