ÎncepețiÎncepe gratuit

Folosirea funcțiilor WINDOW bazate pe rânduri

Funcțiile window lucrează adesea cu un interval bazat pe rânduri, analizând un număr de rânduri înainte sau după rândul curent. În acest exercițiu, vei folosi aceeași interogare de trei ori pentru a crea o funcție window bazată pe rânduri.

Acest exercițiu face parte din cursul

Introducere în BigQuery

Vezi cursul

Exercițiu interactiv practic

Încearcă acest exercițiu completând acest cod de exemplu.

-- 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;
Editează și rulează codul