使用多个 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;