เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การใช้ WINDOW functions แบบอิงแถว

Window functions มักใช้หน้าต่างแบบอิงแถว โดยดูจำนวนแถวก่อนหน้าหรือหลังแถวปัจจุบัน ในแบบฝึกหัดนี้ จะใช้คิวรีเดิมสามครั้งเพื่อสร้าง window function แบบอิงแถว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

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;
แก้ไขและรันโค้ด