STRING_AGG와 ARRAY_CONCAT_AGG 사용하기
앞에서 배운 특별 집계 함수는 세 가지 핵심 그룹으로 나뉘었죠. 이번 연습에서는 문자열과 배열 집계에 초점을 맞춘 두 개의 쿼리를 단계별로 살펴보겠습니다. 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