집계와 함께 사용하는 조인
BigQuery에서 조인은 집계와 함께 자주 사용돼요. 예를 들어, 시간이 지나며 행이 계속 늘어나는 orders 같은 아주 긴 테이블과, 상대적으로 항목 수가 적은 products 테이블이 있다고 가정해 봅시다.
이 연습에서는 제품별 주문 수를 집계해 보세요.
이 연습은 강의의 일부입니다
BigQuery 입문
연습 안내
ecomm_products데이터세트에서 각product_id의 주문 건수를 세세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
WITH orders AS (SELECT
o.order_id,
item.product_id
FROM ecommerce.ecomm_orders o, unnest(o.order_items) item)
SELECT
p.product_id,
COUNT(o.order_id)
FROM orders o
-- Complete the join to the products table
___ ecommerce.ecomm_products p
-- Join the data using the product_id column
___
GROUP BY p.product_id;