Get startedGet started for free

Visualizing charging session duration and cost

Your data visualization team wants to slice-and-dice the charging data in a bit of a different way. They'd like to better understand the duration of each charge at a charging station location on a certain day. They'd also like to compare the cost of each charging session to the average charging cost for that charging station location. Your job is to prepare a dataset for them to visualize this information!

This exercise is part of the course

Window Functions in Snowflake

View Course

Exercise instructions

  • Use a window function to find the proportion of total charging_duration for every session at each charging_station_location.
  • Find the difference between each session's charging cost and the average charging_cost for that charging_station_location; alias the results as cost_vs_avg.
  • Order the results by the charging_station_location and charging_date.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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 ___, ___;
Edit and Run Code