As a user, I want to retrieve the population of people, people living in cities, and people not living in cities in each country so that I can analyze the urbanization trends and demographic distribution across countries #25
SQL:
select Name as Country , sum(Population) as TotalPopulation,
(select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name) as UrbanPopulation,
round((select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name)/sum(Population)100,2) as UrbanPopulation%,
(sum(c.Population) - (select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name)) as RuralPopulation,
round((select(sum(c.Population) - (select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name))/sum(Population)100),2) as RuralPopulation%
from country c group by Name ;
SQL: select Name as Country , sum(Population) as TotalPopulation, (select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name) as UrbanPopulation, round((select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name)/sum(Population)100,2) as
UrbanPopulation%
, (sum(c.Population) - (select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name)) as RuralPopulation, round((select(sum(c.Population) - (select sum(city.Population) from city inner join country on city.CountryCode = country.Code where country.Name=c.Name))/sum(Population)100),2) asRuralPopulation%
from country c group by Name ;Parameters: None