Exercise 8
To create the aggregate_country_emissions_temperatures
view in the carbon_emissions
schema using dbt, follow these instructions:
- 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 view. - Add the dbt configuration block at the beginning of the file to specify the materialization type as a view using the
config
macro. - Write the dbt model code to define the
aggregate_country_emissions_temperatures
view. - Define the columns to be selected for the view as follows:
- Year: Integer
- Country: String
- TotalEmissions: Float
- PerCapitaEmissions: Float
- ShareOfGlobalEmissions: Float
- AverageTemperature: Float
- Use the
ref
macro to reference theco2_emissions_by_country
table and theaggregate_country_temperatures
table. - Join the two tables based on the country name and year.
- Apply any necessary transformations or functions to the columns, such as using the
INITCAP
function to standardize the country names. - Save the file.
By following these instructions and executing the appropriate dbt commands,
you will create the aggregate_country_emissions_temperatures
view in the carbon_emissions
schema.
The view will combine the emissions data from the co2_emissions_by_country
table with the temperature data from the aggregate_country_temperatures
table, using a suitable join condition.
The selected columns will include the year, country, total emissions, per capita emissions, share of global emissions, and average temperature.