IniziaInizia gratis

Using STRING_AGG and ARRAY_CONCAT_AGG

As you recall, the special aggregates fall into three core groups. This exercise will walk through two queries focusing on string and array aggregations. We can explore these two functions using our orders and order_details data.

Questo esercizio fa parte del corso

Introduction to BigQuery

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

-- 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
Modifica ed esegui il codice