1. Learn
  2. /
  3. Courses
  4. /
  5. Reporting in SQL

Exercise

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.

Instructions 1/4

undefined XP
    1
    2
    3
    4
  • Construct a query that pulls the country_gdp by region and country, order the query to show the highest country_gdp at the top, and then filter out all null gdp values.