Skip to content

Commit bf16207

Browse files
refactor 1294
1 parent 3968814 commit bf16207

File tree

1 file changed

+0
-86
lines changed

1 file changed

+0
-86
lines changed

Diff for: database/_1294.sql

-86
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,3 @@
1-
--1294. Weather Type in Each Country
2-
--
3-
--Table: Countries
4-
--
5-
--+---------------+---------+
6-
--| Column Name | Type |
7-
--+---------------+---------+
8-
--| country_id | int |
9-
--| country_name | varchar |
10-
--+---------------+---------+
11-
--country_id is the primary key for this table.
12-
--Each row of this table contains the ID and the name of one country.
13-
--
14-
--
15-
--Table: Weather
16-
--
17-
--+---------------+---------+
18-
--| Column Name | Type |
19-
--+---------------+---------+
20-
--| country_id | int |
21-
--| weather_state | varchar |
22-
--| day | date |
23-
--+---------------+---------+
24-
--(country_id, day) is the primary key for this table.
25-
--Each row of this table indicates the weather state in a country for one day.
26-
--
27-
--
28-
--Write an SQL query to find the type of weather in each country for November 2019.
29-
--
30-
--The type of weather is Cold if the average weather_state is less than or equal 15, Hot if the average weather_state is greater than or equal 25 and Warm otherwise.
31-
--
32-
--Return result table in any order.
33-
--
34-
--The query result format is in the following example:
35-
--
36-
--Countries table:
37-
--+------------+--------------+
38-
--| country_id | country_name |
39-
--+------------+--------------+
40-
--| 2 | USA |
41-
--| 3 | Australia |
42-
--| 7 | Peru |
43-
--| 5 | China |
44-
--| 8 | Morocco |
45-
--| 9 | Spain |
46-
--+------------+--------------+
47-
--Weather table:
48-
--+------------+---------------+------------+
49-
--| country_id | weather_state | day |
50-
--+------------+---------------+------------+
51-
--| 2 | 15 | 2019-11-01 |
52-
--| 2 | 12 | 2019-10-28 |
53-
--| 2 | 12 | 2019-10-27 |
54-
--| 3 | -2 | 2019-11-10 |
55-
--| 3 | 0 | 2019-11-11 |
56-
--| 3 | 3 | 2019-11-12 |
57-
--| 5 | 16 | 2019-11-07 |
58-
--| 5 | 18 | 2019-11-09 |
59-
--| 5 | 21 | 2019-11-23 |
60-
--| 7 | 25 | 2019-11-28 |
61-
--| 7 | 22 | 2019-12-01 |
62-
--| 7 | 20 | 2019-12-02 |
63-
--| 8 | 25 | 2019-11-05 |
64-
--| 8 | 27 | 2019-11-15 |
65-
--| 8 | 31 | 2019-11-25 |
66-
--| 9 | 7 | 2019-10-23 |
67-
--| 9 | 3 | 2019-12-23 |
68-
--+------------+---------------+------------+
69-
--Result table:
70-
--+--------------+--------------+
71-
--| country_name | weather_type |
72-
--+--------------+--------------+
73-
--| USA | Cold |
74-
--| Austraila | Cold |
75-
--| Peru | Hot |
76-
--| China | Warm |
77-
--| Morocco | Hot |
78-
--+--------------+--------------+
79-
--Average weather_state in USA in November is (15) / 1 = 15 so weather type is Cold.
80-
--Average weather_state in Austraila in November is (-2 + 0 + 3) / 3 = 0.333 so weather type is Cold.
81-
--Average weather_state in Peru in November is (25) / 1 = 25 so weather type is Hot.
82-
--Average weather_state in China in November is (16 + 18 + 21) / 3 = 18.333 so weather type is Warm.
83-
--Average weather_state in Morocco in November is (25 + 27 + 31) / 3 = 27.667 so weather type is Hot.
84-
--We know nothing about average weather_state in Spain in November so we don't include it in the result table.
85-
86-
--# Write your MySQL query statement below
871
select c.country_name as country_name,
882
case
893
when avg(weather_state) <= 15 then "Cold"

0 commit comments

Comments
 (0)