doc-exports/docs/dli/sqlreference/dli_08_0436.html
Su, Xiaomeng 04d4597cf3 dli_sqlreference_0511_version
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>
2023-11-02 14:34:08 +00:00

125 lines
11 KiB
HTML

<a name="dli_08_0436"></a><a name="dli_08_0436"></a>
<h1 class="topictitle1">Aggregate Functions</h1>
<div id="body8662426"><p id="dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_en-us_topic_0060575891_p264654433412">An aggregate function performs a calculation operation on a set of input values and returns a value. For example, the COUNT function counts the number of rows retrieved by an SQL statement. <a href="#dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_tb90f8c1797b346ca8ac5fcb1eb5d85df">Table 1</a> lists aggregate functions.</p>
<div class="tablenoborder"><a name="dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_tb90f8c1797b346ca8ac5fcb1eb5d85df"></a><a name="en-us_topic_0000001310215809_dli_08_0104_tb90f8c1797b346ca8ac5fcb1eb5d85df"></a><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_tb90f8c1797b346ca8ac5fcb1eb5d85df" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Aggregate functions</caption><thead align="left"><tr id="dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_r5790c1fe376b4ab2ace8344bdb73e92d"><th align="left" class="cellrowborder" valign="top" width="33.58%" id="mcps1.3.2.2.4.1.1"><p id="dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_a0fa16f0341ac40e5ae8eb21eb74d88d1">Function</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="11.95%" id="mcps1.3.2.2.4.1.2"><p id="dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_aadc2da9326bd497b9122194dd10dd3d7">Return Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="54.47%" id="mcps1.3.2.2.4.1.3"><p id="dli_08_0436__en-us_topic_0000001310215809_dli_08_0104_a1e1d30493581472e9ef62cca2f49dcb4">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0436__en-us_topic_0000001310215809_row162545369308"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p10254193612309">COUNT([ ALL ] expression | DISTINCT expression1 [, expression2]*)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p132544368302">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p192541836153015">Returns the number of input rows for which the expression is not NULL. Use DISTINCT for one unique instance of each value.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row177961646153015"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p13654834117">COUNT(*)</p>
<p id="dli_08_0436__en-us_topic_0000001310215809_p165118144112">COUNT(1)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1079694618309">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1479611462309">Returns the number of input rows.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row14780444113012"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p47803441307">AVG([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1978024453013">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p9780244193018">Returns the average (arithmetic mean) of expression across all input rows.</p>
<p id="dli_08_0436__en-us_topic_0000001310215809_p7422218469">Use DISTINCT for one unique instance of each value.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row346434211304"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p846415423309">SUM([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p20464342153010">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1646414203018">Returns the sum of expression across all input rows.</p>
<p id="dli_08_0436__en-us_topic_0000001310215809_p194796371465">Use DISTINCT for one unique instance of each value.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row06261340193015"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p262644014301">MAX([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p16626240123013">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p3626340103018">Returns the maximum value of expression across all input rows.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row07021738103020"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p570223816305">MIN([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p57026386302">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1970383811305">Returns the minimum value of expression across all input rows.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row6271720154710"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p12742017478">STDDEV_POP([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p827720144716">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p202722014719">Returns the population standard deviation of expression across all input rows.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row1818119179470"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p11181171774714">STDDEV_SAMP([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p161812017124715">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p71811817104711">Returns the sample standard deviation of expression across all input rows.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row1511915149476"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p151191714134712">VAR_POP([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p141196144475">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p611981484713">Returns the population variance (square of the population standard deviation) of expression across all input rows.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row668415112472"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p868431104715">VAR_SAMP([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p16684611154710">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1768441164712">Returns the sample variance (square of the sample standard deviation) of expression across all input rows. </p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row175551819488"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1955508134815">COLLECT([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1255510818482">MULTISET</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p10555148174818">Returns a multiset of expression across all input rows.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row1975646114816"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1675612644819">VARIANCE([ ALL | DISTINCT ] expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p157562684819">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p175611684811">Returns the sample variance (square of the sample standard deviation) of expression across all input rows. </p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row1375974114919"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p14759104144910">FIRST_VALUE(expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1975994204914">Actual type</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p1475984104910">Returns the first value in an ordered set of values.</p>
</td>
</tr>
<tr id="dli_08_0436__en-us_topic_0000001310215809_row18561152194918"><td class="cellrowborder" valign="top" width="33.58%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0436__en-us_topic_0000001310215809_p11561628497">LAST_VALUE(expression)</p>
</td>
<td class="cellrowborder" valign="top" width="11.95%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0436__en-us_topic_0000001310215809_p4561102194914">Actual type</p>
</td>
<td class="cellrowborder" valign="top" width="54.47%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0436__en-us_topic_0000001310215809_p105616294911">Returns the last value in an ordered set of values.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0426.html">Built-In Functions</a></div>
</div>
</div>