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:
- 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.
- 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.
Diese Übung ist Teil des Kurses
Reporting in SQL
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
-- 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 ____;