Sử dụng STRING_AGG và ARRAY_CONCAT_AGG
Như bạn đã nhớ, các phép tổng hợp đặc biệt được chia thành ba nhóm chính. Bài tập này sẽ đi qua hai truy vấn tập trung vào tổng hợp chuỗi và mảng. Ta sẽ khám phá hai hàm này với dữ liệu orders và order_details.
Bài tập này là một phần của khóa học
Giới thiệu về BigQuery
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
-- 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