Exercise 6
Create Table for Aggregate Country Emissions Temperatures
In this exercise, you will create a table that combines the results of the co2_emissions_by_country
table and the aggregate_country_temperatures
table. You will perform an INNER JOIN between these two tables and standardize the country name using the initcap
function.
To create the table aggregate_country_emissions_temperatures
with the desired columns in the carbon_emissions
schema:
- Open your dbt project and navigate to the appropriate schema directory (e.g.,
models/carbon_emissions
). - Create a new file named
aggregate_country_emissions_temperatures.sql
(or any desired name) in the schema directory. - In the
aggregate_country_emissions_temperatures.sql
file, write the dbt model definition for the table. - Define the
aggregate_country_emissions_temperatures
model using thetable
materialization type. - Perform an INNER JOIN between the
co2_emissions_by_country
table and theaggregate_country_temperatures
table using the "Year" and "Country" columns as the join conditions. - Use the
initcap
function to standardize the country name in the "Country" column. - Select the following columns for the output table:
Year
: IntegerCountry
: StringTotalEmissions
: FloatPerCapitaEmissions
: FloatShareOfGlobalEmissions
: FloatAverageTemperature
: Float
By following these instructions and executing the appropriate dbt commands, you will create the table aggregate_country_emissions_temperatures
in the carbon_emissions
schema.
The table will contain the combined results of the emissions and temperatures data, with the specified columns as outlined above.