
# percentile
percentile函数用于返回数值区域的百分比数值点。
#### 命令格式
```
percentile(BIGINT col, p)
```
#### 参数说明
表1参数说明 
| 参数  | 是否必选 | 说明                    |
|:---|:---|:---|
| col | 是    | 数据类型为数值的列。其他类型返回NULL。 |
| p   | 是    | 0\<=P\<=1,否则返回NULL。   |
   
#### 返回值说明
返回DOUBLE类型的值。
![](https://support.huaweicloud.com/sqlref-spark-dli/public_sys-resources/note_3.0-zh-cn.png)
0\<=P\<=1,否则返回NULL。
#### 示例代码
- 计算所有商品库存（items）的 0.5 百分位。命令示例如下：
  ```
  select percentile(items,0.5) from warehouse;
  ```
  返回结果如下：
  ```
  +------------+
  | _c0        |
  +------------+
  | 500.6      |
  +------------+
  ```
  
- 与group by配合使用，对所有商品按照仓库（warehouseId）进行分组，并计算同组商品库存（items）的 0.5 百分位。命令示例如下：
  ```
  select warehouseId, percentile(items, 0.5) from warehouse group by warehouseId;
  ```
  返回结果如下：
  ```
  +------------+------------+
  | warehouseId| _c1        |
  +------------+------------+
  | city1    | 499.6      |
  | city2    | 354.8      |
  | city3    | 565.7      |
  +------------+------------+
  ```
  
 
