開始使用免費開始

擷取日期成分

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;
編輯並執行程式碼