開始使用免費開始

溫度對充電速率的影響

你用視窗函式分析的資料,不只對你的團隊有洞見,對車廠本身也很有用。有幾家製造商想了解溫度對充電速率的影響。他們希望看到溫度的移動平均,以及依車款(vehicle_model)區分的充電速率移動平均。

本練習屬於課程

Snowflake 的 Window Functions

檢視課程

練習說明

  • temperature 排序,使用「前兩筆」與目前列,計算 temperature 的移動平均。
  • 產生另一個移動平均,這次針對 charging_rate,依 temperature 排序並以 vehicle_model 分割分區,使用「前四筆」與目前列。
  • 只包含 charging_rate 不為 NULL 的紀錄。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

SELECT
    vehicle_model,
    charger_type,
    temperature,
    charging_rate,
	
    -- Create a moving average of temperature using the two preceding and following records
    ___(___) OVER(
        PARTITION BY vehicle_model
        ORDER BY ___
        ROWS BETWEEN ___ ___ AND ___ ___
    ) AS moving_average_temperature,
    
    -- Find the moving average charging rate for the preceding four charging sessions
    ___(___) OVER(
        PARTITION BY ___
        ORDER BY ___
        ___
    ) AS moving_average_charging_rate

FROM ELECTRIC_VEHICLES.charging

-- Only include non-NULL charging rates
WHERE ___
ORDER BY vehicle_model, charger_type, temperature;
編輯並執行程式碼