充電時間有變長嗎?
資料科學團隊目前有一個模型,會根據車輛的平均充電時間來預測可用充電樁的數量。這能讓他們在可能適合充電的時機,向先前的使用者發送通知。不過,團隊認為自從上次訓練模型後,平均充電時間可能已經改變。你能幫他們驗證一下嗎?
本練習屬於課程
Snowflake 的 Window Functions
練習說明
- 使用視窗函式計算車輛
charging_duration的遞增平均值(running average)。 - 以
charging_station_location進行分割(partition)。 - 將視窗依
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;