使用多個 CTE
使用多個 CTE 可以大幅提升程式碼的效能與可讀性。這個範例中,你會把一段查詢切成兩個 CTE,讓它更容易閱讀、效能也更好。
本練習屬於課程
BigQuery 入門
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Create a CTE named "orders" that handles the queries for the ecomm_orders table
WITH orders AS (
SELECT ___, items.___, items.___
FROM ecommerce.ecomm_orders, UNNEST(___) items
WHERE items.price > ___
)
SELECT
order_id,
AVG(p.product_weight_g) as avg_weight
FROM orders o
JOIN ecommerce.ecomm_products p ON o.product_id = p.product_id
GROUP BY o.order_id;