Maintaining charger efficiency
As vehicle chargers age, their efficiency often wanes. The operations team is interested in performing proactive maintenance and identifying when a charger may need to be replaced. To do this, they'd like to have a report that tracks the change in charging rate in the last three charges. Let's see if you can give them a hand!
This exercise is part of the course
Window Functions in Snowflake
Exercise instructions
- Use a window function to find the difference between the
charging_rate
for the current session and thecharging_rate
from 3 sessions ago. - Partition the result set data by the
charging_station_location
to make sure that results are isolated to each charging station. - Determine the sequence of sessions using the
charging_start_time
, in ascending order.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
user_id,
charging_station_location,
charging_start_time,
charging_rate,
-- Difference between current charging rate versus three sessions ago
___ - ___(___, ___, 0) OVER(
-- Make sure results are partitioned by charging_station_location
___
-- Sessions should be ordered by when charging began
___
) AS change_in_charging_rate
FROM ELECTRIC_VEHICLES.charging;