Utilizarea STRING_AGG și ARRAY_CONCAT_AGG
Așa cum știi, agregările speciale se împart în trei grupuri principale. Acest exercițiu te va ghida prin două interogări care se concentrează pe agregările de șiruri de caractere și de array-uri. Putem explora aceste două funcții folosind datele din tabelele orders și order_details.
Acest exercițiu face parte din cursul
Introducere în BigQuery
Exercițiu interactiv practic
Încearcă acest exercițiu completând acest cod de exemplu.
-- 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