题目链接:点击打开链接
题目大意:略。
解题思路:注意解决方案(1) LEFT 玩法。
AC 代码
-- 解决方案(1)
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
INNER JOIN WEATHER AS W
ON C.COUNTRY_ID = W.COUNTRY_ID
WHERE LEFT(DAY, 7) = '2019-11'
GROUP BY 1;
-- 解决方案(2)
SELECT country_name, IF(AVG(weather_state) <= 15, 'Cold', IF(AVG(weather_state) >= 25, 'Hot', 'Warm')) weather_type
FROM Weather w JOIN Countries c ON c.country_id = w.country_id
WHERE DATE_FORMAT(day, '%Y-%m') = '2019-11'
GROUP BY w.country_id