开始使用免费开始使用

使用基于行的 WINDOW 函数

窗口函数常使用基于行的窗口,会查看当前行之前或之后的若干行。在本练习中,您将把同一条查询使用三次,来创建一个基于行的窗口函数。

本练习是课程的一部分

BigQuery 入门

查看课程

交互式实操练习

通过完成这段示例代码来试试这个练习。

-- 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;
编辑并运行代码