ComenzarEmpieza gratis

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!

Este ejercicio forma parte del curso

Window Functions in Snowflake

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

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 ___, ___;
Editar y ejecutar código