开始使用免费开始使用

均值与中位数

按行业计算《财富》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 ___;
编辑并运行代码