행 기반 WINDOW 함수 사용하기
윈도 함수는 종종 행 기반 윈도를 사용하여 현재 행의 이전 또는 이후에 있는 여러 행을 함께 살펴봅니다. 이 연습에서는 같은 쿼리를 세 번 활용해 행 기반 윈도 함수를 만들어 보겠습니다.
이 연습은 강의의 일부입니다
BigQuery 입문
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
-- Complete the query to find the rolling average
SELECT
order_id,
order_purchase_timestamp,
-- Aggregate the price to find the average item price
AVG(___)
OVER(
-- Order the query by the purchase timestamp
ORDER BY ___
-- Start the rows window as a between statement
ROWS ___
-- Create the window for the nine previous rows
___ ___
-- Stop the window at the current row
AND ___ ROW) as rolling_avg
FROM ecommerce.ecomm_order_details od
JOIN ecommerce.ecomm_orders o
USING (order_id), unnest(o.order_items) as item
ORDER BY order_purchase_timestamp;