数据湖探索 DLI-percentile:示例代码

时间:2024-07-01 21:07:49

示例代码

  • 计算所有商品库存(items)的 0.5 百分位。命令示例如下:
    select percentile(items,0.5) from warehouse; 

    返回结果如下:

    +------------+
    | _c0        |
    +------------+
    | 500.6      |
    +------------+
  • 与group by配合使用,对所有商品按照仓库(warehourseId)进行分组,并计算同组商品库存(items)的 0.5 百分位。命令示例如下:
    select warehourseId, percentile(items, 0.5) from warehourse group by warehourseId; 

    返回结果如下:

    +------------+------------+
    | warehouseId| _c1        |
    +------------+------------+
    | city1    | 499.6      |
    | city2    | 354.8      |
    | city3    | 565.7      |
    +------------+------------+
support.huaweicloud.com/sqlref-spark-dli/dli_spark_percentile.html