题目描述:
写一段 SQL 来找到表中每个国家在 2019 年 11 月的天气类型。
天气类型的定义如下:当 weather_state 的平均值小于或等于15返回 Cold,当 weather_state 的平均值大于或等于 25 返回 Hot,否则返回 Warm。
你可以以任意顺序返回你的查询结果。
查询结果格式如下所示;
方法1:
主要思路:解题链接汇总
# Write your MySQL query statement below
select country_name as 'country_name',
case
when avg(w1.weather_state)<=15 then 'Cold'
when avg(w1.weather_state)>=25 then 'Hot'
else 'Warm'
end
as 'weather_type'
from Countries as c1 join Weather as w1 on c1.country_id=w1.country_id
where w1.day >= '2019-11-01' AND w1.day <='2019-11-30'
group by c1.country_id