forked from docs/doc-exports
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>
55 lines
4.9 KiB
HTML
55 lines
4.9 KiB
HTML
<a name="dli_spark_avg"></a><a name="dli_spark_avg"></a>
|
|
|
|
<h1 class="topictitle1">avg</h1>
|
|
<div id="body8662426"><p id="dli_spark_avg__en-us_topic_0000001703779881_p18471163815215">This function is used to return the average value.</p>
|
|
<div class="section" id="dli_spark_avg__en-us_topic_0000001703779881_section45291954203217"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_spark_avg__en-us_topic_0000001703779881_screen19928459112517">avg(col), avg(DISTINCT col)</pre>
|
|
</div>
|
|
<div class="section" id="dli_spark_avg__en-us_topic_0000001703779881_section992014913317"><h4 class="sectiontitle">Parameters</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_spark_avg__en-us_topic_0000001703779881_table1829154762513" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter</caption><thead align="left"><tr id="dli_spark_avg__en-us_topic_0000001703779881_row8830104792517"><th align="left" class="cellrowborder" valign="top" width="21.05%" id="mcps1.3.3.2.2.5.1.1"><p id="dli_spark_avg__en-us_topic_0000001703779881_p983074711252">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="10.4%" id="mcps1.3.3.2.2.5.1.2"><p id="dli_spark_avg__en-us_topic_0000001703779881_p6830124732517">Mandatory</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="13.8%" id="mcps1.3.3.2.2.5.1.3"><p id="dli_spark_avg__en-us_topic_0000001703779881_p1564012317529">Type</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="54.75%" id="mcps1.3.3.2.2.5.1.4"><p id="dli_spark_avg__en-us_topic_0000001703779881_p08301547132513">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_spark_avg__en-us_topic_0000001703779881_row15830184792511"><td class="cellrowborder" valign="top" width="21.05%" headers="mcps1.3.3.2.2.5.1.1 "><p id="dli_spark_avg__en-us_topic_0000001703779881_p683034714250">col</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="10.4%" headers="mcps1.3.3.2.2.5.1.2 "><p id="dli_spark_avg__en-us_topic_0000001703779881_p12830184752518">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.8%" headers="mcps1.3.3.2.2.5.1.3 "><p id="dli_spark_avg__en-us_topic_0000001703779881_p86406365211">All data types</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="54.75%" headers="mcps1.3.3.2.2.5.1.4 "><p id="dli_spark_avg__en-us_topic_0000001703779881_p9484232112711">The value can be of any data type and can be converted to the DOUBLE type for calculation.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_spark_avg__en-us_topic_0000001703779881_section210162513312"><h4 class="sectiontitle">Return Values</h4><p id="dli_spark_avg__en-us_topic_0000001703779881_p184124317231">The return value is of the DOUBLE type.</p>
|
|
<div class="note" id="dli_spark_avg__en-us_topic_0000001703779881_note61422099395"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dli_spark_avg__en-us_topic_0000001703779881_p11468110152814">If the value of <strong id="dli_spark_avg__en-us_topic_0000001703779881_b1169818259110">col</strong> is <strong id="dli_spark_avg__en-us_topic_0000001703779881_b18114182815120">NULL</strong>, the column is not involved in calculation.</p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="dli_spark_avg__en-us_topic_0000001703779881_section13277192233920"><h4 class="sectiontitle">Example Code</h4><ul id="dli_spark_avg__en-us_topic_0000001703779881_ul153355539334"><li id="dli_spark_avg__en-us_topic_0000001703779881_li83351653193315">Calculates the average number of items across all warehouses. An example command is as follows:<pre class="screen" id="dli_spark_avg__en-us_topic_0000001703779881_screen530401465820">select avg(items) from warehouse;</pre>
|
|
<p id="dli_spark_avg__en-us_topic_0000001703779881_p11457163219477">The command output is as follows:</p>
|
|
<pre class="screen" id="dli_spark_avg__en-us_topic_0000001703779881_screen1824812303581">_c0
|
|
100.0 </pre>
|
|
</li></ul>
|
|
<ul id="dli_spark_avg__en-us_topic_0000001703779881_ul1566954993312"><li id="dli_spark_avg__en-us_topic_0000001703779881_li86691849103313">Calculates the average inventory of all items in each warehouse when used with <strong id="dli_spark_avg__en-us_topic_0000001703779881_b4408101613611">group by</strong>. An example command is as follows:<pre class="screen" id="dli_spark_avg__en-us_topic_0000001703779881_screen1553758185817">select warehourseId, avg(items) from warehourse group by warehourseId;</pre>
|
|
<p id="dli_spark_avg__en-us_topic_0000001703779881_p13594133204712">The command output is as follows:</p>
|
|
<pre class="screen" id="dli_spark_avg__en-us_topic_0000001703779881_screen196058271331">warehouseId _c1
|
|
city1 155
|
|
city2 101
|
|
city3 194 </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>
|
|
|