Classify each country's November 2019 weather as Cold, Warm or Hot from its average weather state

Quick Overview

A SQL question that labels each country Cold, Warm or Hot from its average weather state over one month and leaves out countries with no readings in that month. It tests joins, filtering a date range with both ends included, grouping with AVG, and CASE thresholds that fall exactly on the boundary values.

Classify each country's November 2019 weather as Cold, Warm or Hot from its average weather state

Company: Point72

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

`Weather` holds one integer `weather_state` reading per country per day. Find the weather type of each country for November 2019 based on its average `weather_state` in that month. A country is `Cold` when the average is at most 15, `Hot` when it is at least 25, and `Warm` otherwise. Countries with no November 2019 data are excluded. Output `country_name` and `weather_type`. ```hint Pin down the month Write out the exact range of dates that counts as November 2019 and check that your filter keeps both its first and its last day, and nothing from November of another year. ``` ### Input Table(s) `Countries`. Primary key: `country_id`. | Column | Type | Meaning | |---|---|---| | country_id | INT | Country identifier (primary key). | | country_name | VARCHAR(50) | Country name, NOT NULL and unique. | `Weather`. Primary key: (`country_id`, `day`). `country_id` references `Countries.country_id`. | Column | Type | Meaning | |---|---|---| | country_id | INT | The country of the reading. | | weather_state | INT | The day's weather state reading. | | day | DATE | The date of the reading. | ### Output Contract - Columns, in this order: `country_name`, `weather_type`. - `weather_type` is exactly one of the strings `'Cold'`, `'Warm'`, `'Hot'`. - One row per country that has at least one reading in November 2019. - Order rows by `country_name` ascending. ### Example `Countries` | country_id | country_name | |---|---| | 1 | Norway | | 2 | Brazil | | 3 | Japan | | 4 | Egypt | | 5 | Chile | `Weather` | country_id | weather_state | day | |---|---|---| | 1 | 10 | 2019-11-03 | | 1 | 20 | 2019-11-20 | | 1 | 35 | 2019-12-01 | | 2 | 20 | 2019-11-10 | | 2 | 30 | 2019-11-30 | | 3 | 40 | 2018-11-15 | | 3 | 18 | 2019-11-01 | | 3 | 21 | 2019-11-15 | | 4 | 28 | 2019-10-31 | | 5 | 15 | 2019-11-05 | | 5 | 16 | 2019-11-06 | Expected result: | country_name | weather_type | |---|---| | Brazil | Hot | | Chile | Warm | | Japan | Warm | | Norway | Cold | Norway's November readings average (10 + 20) / 2 = 15, which counts as Cold; its December reading is ignored. Brazil averages (20 + 30) / 2 = 25, which counts as Hot, and that needs the reading from November 30. Japan averages (18 + 21) / 2 = 19.5 once its 2018 reading is left out, and Chile averages 15.5, so both are Warm. Egypt has no reading in November 2019 and does not appear. ### Constraints and Clarifications - November 2019 runs from 2019-11-01 through 2019-11-30, both days included. Readings on any other date are ignored. - The average is the exact mean of the country's November 2019 readings, with its fractional part kept. An average of 15.5 is Warm. - Both thresholds are inclusive: an average of exactly 15 is Cold and exactly 25 is Hot. - `weather_state` is never NULL. A country has at most one reading per day (the primary key). - Every `country_id` in `Weather` exists in `Countries`. A country with no November 2019 readings, including one with no readings at all, is left out of the result.

Overview: A SQL question that labels each country Cold, Warm or Hot from its average weather state over one month and leaves out countries with no readings in that month. It tests joins, filtering a date range with both ends included, grouping with AVG, and CASE thresholds that fall exactly on the boundary values.

Point72 logo
Point72
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Weather holds one integer weather_state reading per country per day.

Find the weather type of each country for November 2019 based on its average weather_state in that month. A country is Cold when the average is at most 15, Hot when it is at least 25, and Warm otherwise. Countries with no November 2019 data are excluded. Output country_name and weather_type.

Input Table(s)

Countries. Primary key: country_id.

ColumnTypeMeaning
country_idINTCountry identifier (primary key).
country_nameVARCHAR(50)Country name, NOT NULL and unique.

Weather. Primary key: (country_id, day). country_id references Countries.country_id.

ColumnTypeMeaning
country_idINTThe country of the reading.
weather_stateINTThe day's weather state reading.
dayDATEThe date of the reading.

Output Contract

  • Columns, in this order: country_name , weather_type .
  • weather_type is exactly one of the strings 'Cold' , 'Warm' , 'Hot' .
  • One row per country that has at least one reading in November 2019.
  • Order rows by country_name ascending.

Example

Countries

country_idcountry_name
1Norway
2Brazil
3Japan
4Egypt
5Chile

Weather

country_idweather_stateday
1102019-11-03
1202019-11-20
1352019-12-01
2202019-11-10
2302019-11-30
3402018-11-15
3182019-11-01
3212019-11-15
4282019-10-31
5152019-11-05
5162019-11-06

Expected result:

country_nameweather_type
BrazilHot
ChileWarm
JapanWarm
NorwayCold

Norway's November readings average (10 + 20) / 2 = 15, which counts as Cold; its December reading is ignored. Brazil averages (20 + 30) / 2 = 25, which counts as Hot, and that needs the reading from November 30. Japan averages (18 + 21) / 2 = 19.5 once its 2018 reading is left out, and Chile averages 15.5, so both are Warm. Egypt has no reading in November 2019 and does not appear.

Constraints and Clarifications

  • November 2019 runs from 2019-11-01 through 2019-11-30, both days included. Readings on any other date are ignored.
  • The average is the exact mean of the country's November 2019 readings, with its fractional part kept. An average of 15.5 is Warm.
  • Both thresholds are inclusive: an average of exactly 15 is Cold and exactly 25 is Hot.
  • weather_state is never NULL. A country has at most one reading per day (the primary key).
  • Every country_id in Weather exists in Countries . A country with no November 2019 readings, including one with no readings at all, is left out of the result.