시작하기무료로 시작하기

비효율적인 충전기 식별하기

시간이 지날수록 충전기의 효율은 떨어질 수 있습니다. 이런 경우 충전기는 정비가 필요하거나 교체해야 합니다. 충전 속도를 기준으로 충전기의 효율 여부를 판단합니다. 교체가 필요할 수 있는 충전기를 찾기 위해, 윈도우 프레임을 사용해 충전기의 평균 충전 속도와 남은 세션 수를 구하는 쿼리를 작성해 보세요. 화이팅입니다!

이 연습은 강의의 일부입니다

Snowflake의 Window 함수

강의 보기

연습 안내

  • charging_station_location별로 처음 행부터 현재 행까지의 윈도우 프레임을 사용해 평균 charging_rate를 구하세요.
  • charging_station_location별 레코드 수를 세세요.
  • charging_start_time으로 정렬하고, 현재 행부터 마지막 행까지의 윈도우 프레임을 생성하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

SELECT
    user_id,
    TO_DATE(charging_start_time), 
    charging_station_location,
    charging_rate,
	
    -- Find the average charging rate, by charging station location
  	-- using a window frame between the first row and current row
    ___(___) OVER(
        PARTITION BY ___
        ORDER BY charging_start_time
        ROWS BETWEEN ___ ___ AND ___ ___
    ) AS running_average_charging_rate,
	
    -- Count the number of records by charging station location
    ___(*) OVER(
        PARTITION BY charging_station_location
      	
      	-- Create a window frame between the current row and the 
      	-- last row, ordered by charging start time
        ORDER BY ___
        ROWS BETWEEN ___ ___ AND ___ ___
      
    ) AS remaining_charges

FROM ELECTRIC_VEHICLES.charging
ORDER BY charging_station_location, charging_start_time;
코드 편집 및 실행