STRING_AGG en ARRAY_CONCAT_AGG gebruiken
Zoals je je herinnert, vallen de speciale aggregaties in drie hoofdcategorieën. In deze oefening doorloop je twee queries die zich richten op string- en array-aggregaties. We verkennen deze twee functies met onze orders- en order_details-gegevens.
Deze oefening maakt deel uit van de cursus
Introductie tot BigQuery
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
-- 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