Since a GROUP BY is included, global_gdp will require two SUM() functions. -- 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 -- 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
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter