การใช้ STRING_AGG และ ARRAY_CONCAT_AGG
อย่างที่ทราบกัน การรวมข้อมูลแบบพิเศษแบ่งออกเป็น 3 กลุ่มหลัก แบบฝึกหัดนี้จะพาไปทำความรู้จักกับ 2 คิวรีที่เน้นการรวมข้อมูลประเภท string และ array โดยใช้ข้อมูลจากตาราง orders และ order_details
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
BigQuery เบื้องต้น
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
-- 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