CommencerCommencer gratuitement

Utiliser STRING_AGG et ARRAY_CONCAT_AGG

Comme vous vous en souvenez, les agrégats spéciaux se répartissent en trois grands groupes. Cet exercice vous fait parcourir deux requêtes axées sur les agrégations de chaînes et de tableaux. Nous allons explorer ces deux fonctions à partir de nos données orders et order_details.

Cet exercice fait partie du cours

Introduction à BigQuery

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

-- 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
Modifier et exécuter le code