開始使用免費開始

使用以列為基礎的 WINDOW 函式

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;
編輯並執行程式碼