充电时长在变长吗?
数据科学团队目前有一个模型,会根据车辆平均充电时长预测空闲充电桩的数量。这样一来,他们就能在合适的时间提醒之前的用户回来充电。不过,团队认为自上次训练模型以来,平均充电时长可能已经发生变化。您能为他们验证一下吗?
本练习是课程的一部分
Snowflake 中的 Window Functions
练习说明
- 使用窗口函数计算车辆
charging_duration的运行平均值。 - 按
charging_station_location对结果进行分区。 - 按
charging_start_time升序为窗口排序。 - 将记录窗口设置为始终介于第一行和
CURRENT ROW之间。
交互式实操练习
通过完成这段示例代码来试试这个练习。
SELECT
user_id,
charging_station_location,
TO_DATE(charging_start_time),
charging_duration,
-- Find the running average of charging duration
___ OVER(
-- Partition the results by charging_station_location
___
-- Sequence the results by charging start time in ascending order
ORDER BY ___
-- Create the window of records to always be between the
-- first row and the current row
___
) AS running_average
FROM ELECTRIC_VEHICLES.charging;