Usando funções WINDOW baseadas em linhas
As window functions geralmente usam uma janela baseada em linhas, olhando para um número de linhas antes ou depois da linha atual. Neste exercício, você usará a mesma consulta três vezes para criar uma window function baseada em linhas.
Este exercício faz parte do curso
Introdução ao BigQuery
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
-- 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;