Get startedGet started for free

Are charging durations getting longer?

The Data Science team currently has a model that predicts the number of open chargers based on average vehicle charging duration. This allows for them to send notifications to previous users when it might be a good time to charge. However, the team believes that average charging duration may have changed since the last time they trained their model. Can you validate this for them?

This exercise is part of the course

Window Functions in Snowflake

View Course

Exercise instructions

  • Use a window function to find the running average of vehicle charging_duration.
  • Partition the results by charging_station_location.
  • Sequence the window by charging_start_time in ascending order.
  • Create the window of records to always be between the first row and the CURRENT ROW.

Hands-on interactive exercise

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

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