Hacker Rank SQL

Average Population of Each Continent Solution

Hello Friends in this article i am gone to share Hacker Rank SQL Solutions with you | Average Population of Each Continent Solution


Also Visit:ย  African Cities Solution


 

Problem

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:

Field Type
ID NUMBER
NAME VARCHAR2(17)
COUNTRYCODE VARCHAR2(3)
DISTRICT VARCHAR2(20)
POPULATION NUMBER
Field Type
CODE VARCHAR2(3)
NAME VARCHAR2(44)
CONTINENT VARCHAR2(13)
REGION VARCHAR2(25)
SURFACEAREA NUMBER
INDEPYEAR VARCHAR2(5)
POPULATION NUMBER
LIFEEXPECTANCY VARCHAR2(4)
GNP NUMBER
GNPOLD VARCHAR2(9)
LOCALNAME VARCHAR2(44)
GOVERNMENTFORM VARCHAR2(44)
HEADOFSTATE VARCHAR2(32)
CAPITAL VARCHAR2(4)
CODE2 VARCHAR2(2)

 

Solution โ€“ Average Population of Each Continent

MySQL Code
select country.continent, floor(avg(city.population))
from country join city on city.countrycode = country.code
group by country.continent;

 


The average population during a calendar year is calculated as the arithmetic mean of the population on 1st January of two consecutive years. The average population is further used in the calculation of demographic indicators, like the crude rates per 1 000 inhabitants, and for some ‘per capita’ indicators.

What is the average of the world population?

  • 8 Billion

 

Disclaimer: The above Problems are generated by Hacker Rank but the Solutions are Provided by NYANDER.COM. All Hacker Rank SQL Solutions Shared only for Educational and Learning Purpose.