开始使用免费开始使用

创建一个临时表

找出在所属行业中利润位于前 20% 的《财富》500 强公司(相对于其他《财富》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 ___;
编辑并运行代码