Skip to main content

Exercise 1

Create Table for Country Emissions

To create a table called co2_emissions_by_country in the carbon_emissions schema, you will use the data from the STG_EMISSIONS_BY_COUNTRY view to analyze and populate the table.

And TotalEmission column is same as Annual_CO2_emissions column from STG_EMISSIONS_BY_COUNTRY view

Your output table should contain:

  • YEAR: integer
  • COUNTRY: string
  • TOTALEMISSIONS: float
  • PERCAPITAEMISSIONS: float
  • SHAREOFGLOBALEMISSIONS: float

Sample Output

YEARCOUNTRYTOTALEMISSIONSPERCAPITAEMISSIONSSHAREOFGLOBALEMISSIONS
1978Suriname2.3918616.6811760.012616
1979Suriname2.2927686.386540.011779
tip

To handle null values and convert a column to an integer using COALESCE or NULLIF and CAST, use the following expression:

CAST(COALESCE(column_name, 0) AS INTEGER) AS new_column

This will replace null values in the column_name with 0 before casting it to an integer. Adjust the column name and replacement value as needed in your specific case.

note

In the SQL statement, the use of double quotes around the YEAR column name is necessary because it is a reserved keyword in Snowflake.

select "YEAR" FROM TABLE