平均數與中位數
計算《財星 500 大》公司依產業別的平均(avg())與中位數資產。
使用 percentile_disc() 函式來計算中位數:
percentile_disc(0.5)
WITHIN GROUP (ORDER BY column_name)
本練習屬於課程
SQL 中的探索式資料分析
練習說明
- 選取
assets的平均與中位數。 - 依
sector分組。 - 依平均數排序結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
-- What groups are you computing statistics by?
SELECT ___,
-- Select the mean of assets with the avg function
___ AS mean,
-- Select the median
___(___) ___ ___ (___ ___ ___) AS median
FROM fortune500
-- Computing statistics for each what?
GROUP BY ___
-- Order results by a value of interest
ORDER BY ___;