集計を伴う結合
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;