気温が充電速度に与える影響
これまでウィンドウ関数を使って分析してきたデータは、チームにとって有益なだけでなく、自動車メーカーにとっても非常に役立つものです。複数のメーカーから、気温が充電速度に与える影響について調査してほしいという依頼が来ています。気温の移動平均と、車両モデル別に集計した充電速度の移動平均を求めましょう。
この演習はコースの一部です
Snowflake のウィンドウ関数
演習の手順
temperatureで並べ替えた上で、直前の 2 レコードと現在の行を使ってtemperatureの移動平均を求めましょう。- 同様に
temperatureで並べ替え、vehicle_modelでパーティション分割した上で、直前の 4 レコードと現在の行を使ってcharging_rateの移動平均を求めましょう。 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;