擷取日期成分
Coffee County 氣象站有一支量測風速的風速計是否在維修後正常運作,出現了一些疑慮。建議比較每個月的「有風」讀值次數,來判斷它是否在 2023 年 10 月前已修復。
本練習屬於課程
Redshift 入門
練習說明
- 從
date欄位取出年份,並取別名為year。 - 從
date欄位取出月份,並取別名為month。 - 只有在
hourlywindspeed不等於'0'時才計數,方法是回傳數字 1。 - 依年份與月份(依此順序)進行分組與排序。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Get the year from date as year
SELECT ___(___, date) as year,
-- Get the month from date as month
___(___, ___) as ___,
-- Count readings when the hourlywindspeed isn't '0'
COUNT(
CASE WHEN ___ != '0' THEN ___
ELSE NULL
END
)
FROM public_intro_redshift.coffee_county_weather
-- Group and order by the dateparts you extracted
GROUP BY ___, ___
ORDER BY ___ DESC, ___ DESC;