使用 HAVING 进行筛选
HAVING 的用法与 WHERE 子句相同,但它可以将聚合作为条件。这有助于在聚合查询的结果上进一步筛选,找到更具体的趋势。
在本练习中,您需要找出平均重量超过某个阈值的所有产品类别,从而识别那些因重量可能产生更高运费的类别。
本练习是课程的一部分
BigQuery 入门
练习说明
- 补全查询:从
ecommerce.ecomm_products表中,按产品类别 (product_category_name_english) 分组,计算平均产品重量 (product_weight_g)。 - 使用
HAVING查找平均重量超过 10,000 克的产品类别。
交互式实操练习
通过完成这段示例代码来试试这个练习。
-- Write a query that finds all product categories and their average weight with an average weight over 10,000 grams
SELECT
-- Add the product_category_name_english column and the average weight
___
FROM ecommerce.ecomm_products
-- Add the GROUP BY statement
___
-- Add the HAVING condition on the average weight aggregate
___