開始使用免費開始

充電時間有變長嗎?

資料科學團隊目前有一個模型,會根據車輛的平均充電時間來預測可用充電樁的數量。這能讓他們在可能適合充電的時機,向先前的使用者發送通知。不過,團隊認為自從上次訓練模型後,平均充電時間可能已經改變。你能幫他們驗證一下嗎?

本練習屬於課程

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