Advertisement
Guest User

population

a guest
Jul 17th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.34 KB | None | 0 0
  1. -- How many entries in the database are from Africa?
  2.  
  3. SELECT COUNT(*) FROM countries WHERE
  4. continent = 'Africa';
  5.  
  6. -- What was the total population of Oceania in 2005?
  7.  
  8. SELECT SUM(population) FROM population_years
  9. INNER JOIN countries ON
  10. countries.id = population_years.country_id
  11. WHERE YEAR = 2005
  12. AND continent = 'Oceania';
  13.  
  14. -- What is the average population of countries in South America in 2003?
  15.  
  16. SELECT AVG(population) FROM population_years
  17. INNER JOIN countries ON
  18. countries.id = population_years.country_id
  19. WHERE YEAR = 2003
  20. AND continent = 'South America';
  21.  
  22. -- What country had the smallest population in 2007?
  23.  
  24. SELECT MIN(population), name FROM population_years
  25. INNER JOIN countries ON
  26. countries.id = population_years.country_id
  27. WHERE YEAR = 2007;
  28.  
  29. -- What is the average population of Poland during the time period covered by this dataset?
  30.  
  31. SELECT AVG(population), name FROM population_years
  32. INNER JOIN countries ON
  33. countries.id = population_years.country_id
  34. WHERE name = 'Poland';
  35.  
  36. -- How many countries have the word "The" in their name?
  37.  
  38. SELECT COUNT(*) FROM countries
  39. WHERE name LIKE "%The%";
  40.  
  41. -- What was the total population of each continent in 2010?
  42.  
  43. SELECT SUM(population), continent FROM population_years
  44. INNER JOIN countries ON
  45. countries.id = population_years.country_id
  46. WHERE YEAR = 2010
  47. GROUP BY continent;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement