Menggunakan fungsi WINDOW berbasis baris
Fungsi window sering menggunakan jendela berbasis baris, dengan melihat sejumlah baris sebelum atau setelah baris saat ini. Pada latihan ini, Anda akan menggunakan kueri yang sama tiga kali untuk membuat fungsi window berbasis baris.
Latihan ini merupakan bagian dari kursus
Pengantar BigQuery
Latihan interaktif langsung praktik
Cobalah latihan ini dengan melengkapi kode contoh ini.
-- 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;