始める無料で始める

一時テーブルの作成

各セクターの上位20%に入る利益を持つFortune 500企業を見つけましょう(同じFortune 500企業同士で比較します)。

そのためにまず、次の関数を使って各セクターの利益の80パーセンタイルを求めます。

percentile_disc(fraction) 
WITHIN GROUP (ORDER BY sort_expression)

結果を一時テーブルに保存してください。

次に、fortune500を一時テーブルと結合し、利益が80パーセンタイルの基準値を超える企業を選択します。

この演習はコースの一部です

SQLによる探索的データ分析

コースを見る

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

-- To clear table if it already exists; fill in name of temp table
DROP TABLE IF EXISTS ___;

-- Create the temporary table
___ ___ ___ ___ AS 
  -- Select the two columns you need; alias as needed
  SELECT ___, 
         ___(___) ___ (___) AS ___
    -- What table are you getting the data from?
    ___ ___
   -- What do you need to group by?
   ___ ___ ___;
   
-- See what you created: select all columns and rows from the table you created
SELECT * 
  FROM ___;
コードを編集して実行