LOAD the DATA
%%capture
%load_ext sql
%sql sqlite:///factbook.db
EXPLORE THE DATA
%%sql
SELECT *
FROM sqlite_master
WHERE type='table'
%%sql
SELECT *
FROM facts
Limit 5
%%sql
SELECT MIN(population),MAX(population),MIN(population_growth),MAX(population_growth)
FROM facts
%%sql
SELECT *
FROM facts
where population == (select min(population)from facts)
Write a query that returns the countrie(s) with the minimum population.
%%sql
SELECT *
FROM facts
where population == (select max(population)from facts)
Write a query that returns the countrie(s) with the maximum population.
%%sql
SELECT name,MIN(population),MAX(population),MIN(population_growth),MAX(population_growth)
FROM facts
WHERE name <> 'World'
%%sql
SELECT AVG(population) , AVG(area)
FROM facts
WHERE name <> 'World'
Finding Densely Populated Countries¶ To finish, we'll build on the query above to find countries that are densely populated. We'll identify countries that have:
Above average values for population. Below average values for area.
%%sql
SELECT *
FROM facts
WHERE population > (SELECT AVG(population)
FROM facts
WHERE name <> 'World')
AND
area < ( SELECT AVG(area)
FROM facts
WHERE name <> 'World')