使用 STRING_AGG 与 ARRAY_CONCAT_AGG
如您所记得,特殊聚合可分为 3 组核心类型。本练习将通过两个查询来聚焦字符串与数组聚合。我们将使用 orders 与 order_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