IniziaInizia gratis

Uso delle funzioni WINDOW basate sulle righe

Le window function spesso utilizzano una finestra basata sulle righe, considerando un certo numero di righe prima o dopo la riga corrente. In questo esercizio userai la stessa query tre volte per creare una window function basata sulle righe.

Questo esercizio fa parte del corso

Introduzione a BigQuery

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

-- 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;
Modifica ed esegui il codice