doc-exports/docs/dli/sqlreference/dli_spark_percentile.html
Su, Xiaomeng 76a5b1ee83 dli_sqlreference_20240227
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2024-03-27 22:02:33 +00:00

57 lines
5.7 KiB
HTML

<a name="dli_spark_percentile"></a><a name="dli_spark_percentile"></a>
<h1 class="topictitle1">percentile</h1>
<div id="body8662426"><p id="dli_spark_percentile__en-us_topic_0000001655540538_p18471163815215">This function is used to return the numerical value at a certain percentage point within a range of values.</p>
<div class="section" id="dli_spark_percentile__en-us_topic_0000001655540538_section45291954203217"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_spark_percentile__en-us_topic_0000001655540538_screen19928459112517">percentile(BIGINT col, p)</pre>
</div>
<div class="section" id="dli_spark_percentile__en-us_topic_0000001655540538_section992014913317"><h4 class="sectiontitle">Parameters</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_spark_percentile__en-us_topic_0000001655540538_table1829154762513" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="dli_spark_percentile__en-us_topic_0000001655540538_row8830104792517"><th align="left" class="cellrowborder" valign="top" width="22.759999999999998%" id="mcps1.3.3.2.2.4.1.1"><p id="dli_spark_percentile__en-us_topic_0000001655540538_p983074711252">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="15.920000000000002%" id="mcps1.3.3.2.2.4.1.2"><p id="dli_spark_percentile__en-us_topic_0000001655540538_p6830124732517">Mandatory</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="61.31999999999999%" id="mcps1.3.3.2.2.4.1.3"><p id="dli_spark_percentile__en-us_topic_0000001655540538_p08301547132513">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_spark_percentile__en-us_topic_0000001655540538_row15830184792511"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.3.3.2.2.4.1.1 "><p id="dli_spark_percentile__en-us_topic_0000001655540538_p683034714250">col</p>
</td>
<td class="cellrowborder" valign="top" width="15.920000000000002%" headers="mcps1.3.3.2.2.4.1.2 "><p id="dli_spark_percentile__en-us_topic_0000001655540538_p12830184752518">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.31999999999999%" headers="mcps1.3.3.2.2.4.1.3 "><p id="dli_spark_percentile__en-us_topic_0000001655540538_p9484232112711">Columns with a data type of numeric. If the values are of any other type, <strong id="dli_spark_percentile__en-us_topic_0000001655540538_b121262212631238">NULL</strong> is returned.</p>
</td>
</tr>
<tr id="dli_spark_percentile__en-us_topic_0000001655540538_row10507813155613"><td class="cellrowborder" valign="top" width="22.759999999999998%" headers="mcps1.3.3.2.2.4.1.1 "><p id="dli_spark_percentile__en-us_topic_0000001655540538_p350711365611">p</p>
</td>
<td class="cellrowborder" valign="top" width="15.920000000000002%" headers="mcps1.3.3.2.2.4.1.2 "><p id="dli_spark_percentile__en-us_topic_0000001655540538_p35078134566">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="61.31999999999999%" headers="mcps1.3.3.2.2.4.1.3 "><p id="dli_spark_percentile__en-us_topic_0000001655540538_p1518172020590">The value should be between 0 and 1. Otherwise, <strong id="dli_spark_percentile__en-us_topic_0000001655540538_b1148214317574">NULL</strong> is returned.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_spark_percentile__en-us_topic_0000001655540538_section210162513312"><h4 class="sectiontitle">Return Values</h4><p id="dli_spark_percentile__en-us_topic_0000001655540538_p184124317231">The return value is of the DOUBLE type.</p>
<div class="note" id="dli_spark_percentile__en-us_topic_0000001655540538_note61422099395"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dli_spark_percentile__en-us_topic_0000001655540538_p1398125525916">The value should be between 0 and 1. Otherwise, <strong id="dli_spark_percentile__en-us_topic_0000001655540538_b47591119430">NULL</strong> is returned.</p>
</div></div>
</div>
<div class="section" id="dli_spark_percentile__en-us_topic_0000001655540538_section13277192233920"><h4 class="sectiontitle">Example Code</h4><ul id="dli_spark_percentile__en-us_topic_0000001655540538_ul717013205372"><li id="dli_spark_percentile__en-us_topic_0000001655540538_li131701920143717">Calculates the 0.5 percentile of all offering inventories (items). An example command is as follows:<pre class="screen" id="dli_spark_percentile__en-us_topic_0000001655540538_screen3296143152411">select stddev_samp(items,0.5) from warehouse; </pre>
<p id="dli_spark_percentile__en-us_topic_0000001655540538_p1029684382418">The command output is as follows:</p>
<pre class="screen" id="dli_spark_percentile__en-us_topic_0000001655540538_screen1229615432245">_c0
500.6 </pre>
</li><li id="dli_spark_percentile__en-us_topic_0000001655540538_li1433992915378">When used with <strong id="dli_spark_percentile__en-us_topic_0000001655540538_b1391623846">group by</strong>, it groups all offerings by warehouse (warehourseId) and returns the 0.5 percentile of the offering inventory (items) in the same group. An example command is as follows:<pre class="screen" id="dli_spark_percentile__en-us_topic_0000001655540538_screen1929664310245">select warehourseId, stddev_samp(items, 0.5) from warehourse group by warehourseId; </pre>
<p id="dli_spark_percentile__en-us_topic_0000001655540538_p5296134352415">The command output is as follows:</p>
<pre class="screen" id="dli_spark_percentile__en-us_topic_0000001655540538_screen5296143162418">warehouseId _c1
city1 499.6
city2 354.8
city3 565.7 </pre>
</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0474.html">Aggregate Functions</a></div>
</div>
</div>