CommencerCommencer gratuitement

Utiliser des fonctions WINDOW basées sur les lignes

Les fonctions de fenêtre utilisent souvent une fenêtre basée sur les lignes, en examinant un certain nombre de lignes avant ou après la ligne courante. Dans cet exercice, vous allez exécuter la même requête trois fois pour créer une fonction de fenêtre basée sur les lignes.

Cet exercice fait partie du cours

Introduction à BigQuery

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

-- 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;
Modifier et exécuter le code