text: -- Pull country_gdp by region and country
  SELECT 
  	region,
      country,
  	SUM (gdp) AS country_gdp
  FROM country_stats AS cs
  JOIN countries AS c
  ON cs.country_id = c.id
  -- Filter out null gdp values
  WHERE gdp IS NOT NULL
  GROUP BY region, country
  -- Show the highest country_gdp at the top
  ORDER BY country_gdp DESC;
  
  
  -- Pull country_gdp by region and country
  SELECT 
  	region,
      country,
  	SUM(gdp) AS country_gdp,
      -- Calculate the global gdp
      SUM(SUM(gdp)) OVER () AS global_gdp
  FROM country_stats AS cs
  JOIN countries AS c
  ON cs.country_id = c.id
  -- Filter out null gdp values
  WHERE gdp IS NOT NULL
  GROUP BY region, country
  -- Show the highest country_gdp at the top
  ORDER BY country_gdp DESC;
  
  
  -- Pull country_gdp by region and country
  SELECT 
  	region,
      country,
  	SUM(gdp) AS country_gdp,
      -- Calculate the global gdp
      SUM(SUM(gdp)) OVER () AS global_gdp,
      -- Calculate percent of global gdp
      SUM(gdp) / SUM(SUM(gdp)) OVER () AS perc_global_gdp
  FROM country_stats AS cs
  JOIN countries AS c
  ON cs.country_id = c.id
  -- Filter out null gdp values
  WHERE gdp IS NOT NULL
  GROUP BY region, country
  -- Show the highest country_gdp at the top
  ORDER BY country_gdp DESC;
  
  
  -- Pull country_gdp by region and country
  SELECT 
  	region,
      country,
  	SUM(gdp) AS country_gdp,
      -- Calculate the global gdp
      SUM(SUM(gdp)) OVER () AS global_gdp,
      -- Calculate percent of global gdp
      SUM(gdp) / SUM(SUM(gdp)) OVER () AS perc_global_gdp,
      -- Calculate percent of gdp relative to its region
      SUM(gdp) / SUM(SUM(gdp)) OVER (PARTITION BY region) AS perc_region_gdp
  FROM country_stats AS cs
  JOIN countries AS c
  ON cs.country_id = c.id
  -- Filter out null gdp values
  WHERE gdp IS NOT NULL
  GROUP BY region, country
  -- Show the highest country_gdp at the top
  ORDER BY country_gdp DESC;
  
  
  -- Bring in region, country, and gdp_per_million
  SELECT 
      region,
      country,
      SUM(gdp) / SUM(pop_in_millions) AS gdp_per_million
  -- Pull from country_stats_clean
  FROM country_stats_clean AS cs
  JOIN countries AS c 
  ON cs.country_id = c.id
  -- Filter for 2016 and remove null gdp values
  WHERE year = '2016-01-01' AND gdp IS NOT NULL
  GROUP BY region, country
  -- Show highest gdp_per_million at the top
  ORDER BY gdp_per_million DESC;
  
  
  -- Bring in region, country, and gdp_per_million
  SELECT 
      region,
      country,
      SUM(gdp) / SUM(pop_in_millions) AS gdp_per_million,
      -- Output the worlds gdp_per_million
      SUM(SUM(gdp)) OVER () / SUM(SUM(pop_in_millions)) OVER ()  AS gdp_per_million_total
  -- Pull from country_stats_clean
  FROM country_stats_clean AS cs
  JOIN countries AS c 
  ON cs.country_id = c.id
  -- Filter for 2016 and remove null gdp values
  WHERE year = '2016-01-01' AND gdp IS NOT NULL
  GROUP BY region, country
  -- Show highest gdp_per_million at the top
  ORDER BY gdp_per_million DESC;
  
  
  -- Bring in region, country, and gdp_per_million
  SELECT 
      region,
      country,
      SUM(gdp) / SUM(pop_in_millions) AS gdp_per_million,
      -- Output the worlds gdp_per_million
      SUM(SUM(gdp)) OVER () / SUM(SUM(pop_in_millions)) OVER () AS gdp_per_million_total,
      -- Build the performance_index in the 3 lines below
      (SUM(gdp) / SUM(pop_in_millions))
      /
      (SUM(SUM(gdp)) OVER () / SUM(SUM(pop_in_millions)) OVER ()) AS performance_index
  -- Pull from country_stats_clean
  FROM country_stats_clean AS cs
  JOIN countries AS c 
  ON cs.country_id = c.id
  -- Filter for 2016 and remove null gdp values
  WHERE year = '2016-01-01' AND gdp IS NOT NULL
  GROUP BY region, country
  -- Show highest gdp_per_million at the top
  ORDER BY gdp_per_million DESC;
  