Get startedGet started for free

Percent of gdp per country

A percent of total calculation is a good way to compare volume metrics across groups. While simply showing the volume metric in a report provides some insights, adding a ratio allows us to easily compare values quickly.

To run a percent of total calculation, take the following steps:

  1. Create a window function that outputs the total volume, partitioned by whatever is considered the total. If the entire table is considered the total, then no partition clause is needed.
  2. Run a ratio that divides each row's volume metric by the total volume in the partition.

In this exercise, you will calculate the percent of gdp for each country relative to the entire world and relative to that country's region.

This exercise is part of the course

Reporting in SQL

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Pull country_gdp by region and country
SELECT 
	____,
    ____,
	____ AS country_gdp
FROM ____ AS cs
JOIN ____ AS c
ON ____
-- Filter out null gdp values
WHERE ____
GROUP BY ____
-- Show the highest country_gdp at the top
ORDER BY ____;
Edit and Run Code