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

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

示例代码

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

    返回结果如下:

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

    返回结果如下:

    +------------+------------+
    | warehouseId| _c1        |
    +------------+------------+
    | city1    | 499     |
    | city2    | 354     |
    | city3    | 565     |
    +------------+------------+
support.huaweicloud.com/sqlref-spark-dli/dli_spark_percentile_approx.html