開始使用免費開始

使用 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
___
編輯並執行程式碼