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.
| 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.