LoslegenKostenlos loslegen

Joins with aggregations

Joins in BigQuery are often combined with aggregations. For example, imagine you have a very long table like our orders table, which has many entries and can expand over time, and our products table, which has fewer entries.

In this exercise, you must count the number of orders per product.

Diese Übung ist Teil des Kurses

Introduction to BigQuery

Kurs anzeigen

Anleitung zur Übung

  • Count the number of orders for each product_id in the ecomm_products dataset.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

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;
Code bearbeiten und ausführen