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!
Cet exercice fait partie du cours
Window Functions in Snowflake
Instructions
- Use a window function to find the proportion of total
charging_duration
for every session at eachcharging_station_location
. - Find the difference between each session's charging cost and the average
charging_cost
for thatcharging_station_location
; alias the results ascost_vs_avg
. - Order the results by the
charging_station_location
andcharging_date
.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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 ___, ___;