開始使用免費開始

使用 STRING_AGG 與 ARRAY_CONCAT_AGG

回想一下,這些特殊聚合可以分成三大類。本練習將帶你走過兩個查詢,重點在字串與陣列的聚合。我們會用 ordersorder_details 資料來探索這兩個函式。

本練習屬於課程

BigQuery 入門

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

-- Fill in the query to find the distinct product categories for each order

SELECT
    o.order_id,  
    -- Use the STRING_AGG to find distinct values and separate them by a comma with a space
    ___(___ product_category_name_english, ___) AS categories
FROM
    ecommerce.ecomm_orders o, UNNEST(order_items) items
JOIN
    ecommerce.ecomm_products p ON items.product_id = p.product_id
-- Find the number of items in the order_items column
WHERE ___(o.order_items) > 1
GROUP BY
    order_id
編輯並執行程式碼