開始使用免費開始

使用 HAVING 篩選

你的最後一個關鍵字是 HAVING。它與 WHERE 類似,都是用來篩選的子句,不同之處在於 HAVING 用來篩選「已分組」的資料。

在處理大型資料集時,篩選分組後的資料特別實用。當你面對成千上萬甚至上百萬列時,HAVING 能讓你只篩選出想要的資料群組,例如時長超過 2 小時的電影!

練習使用 HAVING,找出哪些國家(或哪一個國家)的電影分級最為多樣。

本練習屬於課程

SQL 中級

檢視課程

練習說明

  • films 資料表選取 country,並取得 certification 的不重複計數,將其命名為 certification_count
  • country 將結果分組。
  • 篩選分級的唯一計數僅保留大於 10 的結果。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

-- Select the country and distinct count of certification as certification_count
___
-- Group by country
___
-- Filter results to countries with more than 10 different certifications
___
編輯並執行程式碼