Leetcode Problem 1294. Weather Type in Each Country

1294. Weather Type in Each Country

Leetcode Solutions

Calculating Weather Type Based on Average Weather State

  1. Filter the Weather table to include only entries from November 2019.
  2. Calculate the average weather_state for each country_id within the filtered date range.
  3. Use a CASE statement to categorize the average weather state into 'Cold', 'Hot', or 'Warm'.
  4. Join the resulting table with the Countries table to get the corresponding country_name for each country_id.
  5. Select the country_name and the determined weather_type for the final output.
  6. Ensure the query groups the results by country_id to calculate the average weather state per country.
erDiagram
    Countries {
        int country_id PK
        varchar country_name
    }
    Weather {
        int country_id PK
        int weather_state
        date day PK
    }
    Countries ||--o{ Weather : has

Using Subquery to Calculate Average Weather State

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...