開始使用免費開始

視覺化充電時長與費用

你的資料視覺化團隊想用不同的角度切分充電資料。他們想更了解在特定日期、特定充電站位置中,每次充電的持續時間。他們也想比較每次充電的費用,與該充電站位置的平均充電費用之間的差異。你的工作是先準備好一個資料集,讓他們能夠將這些資訊視覺化!

本練習屬於課程

Snowflake 的 Window Functions

檢視課程

練習說明

  • 使用視窗函式,計算在每個 charging_station_location 中,每次充電的 charging_duration 佔總量的比例。
  • 計算每次充電費用與該 charging_station_location 的平均 charging_cost 之差;將結果命名為 cost_vs_avg
  • charging_station_locationcharging_date 排序結果。

動手互動練習

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

SELECT
    charging_station_location,
    TO_DATE(charging_start_time) AS charging_date,
    charging_duration,
    charging_cost,
	
    -- Find the proportion of total charging duration charging location
    charging_duration / ___(___) OVER(
        PARTITION BY ___
    ) AS proportion_of_daily_charging_duration,
	
    -- Determine the difference between each session's charging 
    -- cost and the average charging cost for each charging station location
    charging_cost - ___(___) OVER (
        PARTITION BY ___
    ) AS ___

FROM ELECTRIC_VEHICLES.charging

-- Order the results by charging station location and charging date
ORDER BY ___, ___;
編輯並執行程式碼