지금까지 배운 내용을 모두 합쳐 봅시다!
드디어입니다! 이제 배운 모든 내용을 종합해 볼 차례예요. 당신의 회사 CEO가 각 충전 위치의 핵심 지표를 심층적으로 볼 수 있는 대시보드를 요청했어요. 여기에는 소비 전력과 충전 비용 같은 데이터가 포함돼요. 이 대시보드를 만들기 전에, 이러한 정보를 한눈에 파악할 수 있는 데이터세트를 먼저 만들어야 해요.
이 연습은 강의의 일부입니다
Snowflake의 Window 함수
연습 안내
- 특정
charging_station_location에서energy_consumed를 기준으로, 큰 값에서 작은 값 순으로 각 충전 세션의 순위를 매기세요. charging_station_location별로charging_cost의 러닝 합계를 생성하세요.- 앞의 두 개 세션과 뒤의 두 개 세션을 사용하는 윈도우 프레임을 구성하여,
charging_station_location별energy_consumed의 이동 평균을 구하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
SELECT
charging_station_location,
TO_DATE(charging_start_time),
charging_cost,
energy_consumed,
-- Provide a ranking for each charging session based on energy consumed, from greatest to least
___() OVER(
PARTITION BY charging_station_location
ORDER BY ___
) AS rank_energy_consumed,
-- Generate a "running total" of charging costs by charging station location
SUM(___) OVER(
___ ___ ___
ORDER BY charging_start_time
ROWS BETWEEN ___ ___ AND ___ ___
) AS running_total_charging_cost,
-- Build a window frame using the two preceding and two following sessions to find a moving average of energy consumed
___() OVER(
PARTITION BY ___
ORDER BY charging_start_time
ROWS BETWEEN ___ ___ AND ___ ___
) AS moving_average_energy_consumed
FROM ELECTRIC_VEHICLES.charging
WHERE energy_consumed IS NOT NULL
ORDER BY charging_station_location, charging_start_time;