开始使用免费开始使用

提取日期部分

有人担心 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;
编辑并运行代码