HAVING 與排序
篩選與排序常常一起使用,藉由對結果排序,可以讓你更容易解讀。
現在就透過一個查詢來看看效果:找出哪些國家的平均電影預算最高。
本練習屬於課程
SQL 中級
練習說明
- 從
films中選取country,以及四捨五入到小數點後第 2 位的平均預算作為average_budget。 - 依
country對結果分組。 - 僅保留平均預算超過 10 億(
1000000000)的國家。 - 依
average_budget由大到小排序。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- Select the country and average_budget from films
___
-- Group by country
___
-- Filter to countries with an average_budget of more than one billion
___
-- Order by descending order of the aggregated budget
___