平均値と中央値
Fortune 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 ___;