这道题主要的点在于
1、所需要判别类别的天气是在固定月份
2、要用case when来进行分组
3、有的国家没有数据,如果用left join就会出现null,如果不连接用两个表查询,在where中连接就可以
给出答案
SELECT country_name,
CASE
WHEN AVG(weather_state) <= 15 THEN 'Cold'
WHEN AVG(weather_state) >= 25 THEN 'Hot'
ELSE 'Warm'
END
AS weather_type
FROM Countries AS c
LEFT JOIN Weather AS w
ON c.country_id = w.country_id
AND w.day BETWEEN '2019-11-01' AND '2019-11-30'
WHERE w.day IS NOT NULL
GROUP BY country_name