提取日期部分
有人担心 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;