行ベースのWINDOW関数を使う
Window関数は、現在の行の前後にある一定数の行を参照する行ベースのウィンドウを取ることがよくあります。この演習では、同じクエリを3回使って、行ベースの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;