STRING_AGG と ARRAY_CONCAT_AGG を使う
特別な集計関数は、思い出していただくと3つの主要なグループに分類されます。この演習では、文字列と配列の集約に焦点を当てた2つのクエリを順に実行します。orders と order_details のデータを使って、これら2つの関数を確認していきます。
この演習はコースの一部です
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