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>
124 lines
13 KiB
HTML
124 lines
13 KiB
HTML
<a name="dli_08_0068"></a><a name="dli_08_0068"></a>
|
|
|
|
<h1 class="topictitle1">Aggregate Functions</h1>
|
|
<div id="body8662426"><p id="dli_08_0068__en-us_topic_0093946736_adc2804101cf84a33ba636ede09743b5f">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_0068__en-us_topic_0093946736_ta65eaa8782c7472bb0237b75d986c133">Table 1</a> lists aggregate functions.</p>
|
|
|
|
<div class="tablenoborder"><a name="dli_08_0068__en-us_topic_0093946736_ta65eaa8782c7472bb0237b75d986c133"></a><a name="en-us_topic_0093946736_ta65eaa8782c7472bb0237b75d986c133"></a><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0068__en-us_topic_0093946736_ta65eaa8782c7472bb0237b75d986c133" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Aggregate functions</caption><thead align="left"><tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row45266775153322"><th align="left" class="cellrowborder" valign="top" width="24.310000000000002%" id="mcps1.3.2.2.4.1.1"><p id="dli_08_0068__en-us_topic_0093946736_a0ab9d1ad2f2c40b0bdc2c8bf7c02a0d1">Function</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="18.77%" id="mcps1.3.2.2.4.1.2"><p id="dli_08_0068__en-us_topic_0093946736_ab114b052136d46e89719d9e1c8770fc5">Return Type</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="56.92%" id="mcps1.3.2.2.4.1.3"><p id="dli_08_0068__en-us_topic_0093946736_a345303e992984499aeb732dd33537859">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row65432843153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a01ab69116a3246f7ac2851210539ddc7">count(*), count(expr), count(DISTINCT expr[, expr...])</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_ad054490b1d934fdea3f1ad2b708d4131">BIGINT</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a813ab816e7254e209bfbc4776345fd87">Return the total number of retrieved records.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row66958990153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a96a2fb116da84b37937a2225a09bb8ac">sum(col), sum(DISTINCT col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a96b90179654d41acbf44b4e676c44621">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a4874e963132d40eea4369d4289d218ec">Return the sum of the values in a column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row18906918153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a7ba748178a914799b9875b1b71121a61">avg(col), avg(DISTINCT col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_ac8078dd60a1c40bcaa064d55467c3ba8">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a7dc8e63f10e4467cac3395d3c48bd898">Return the average of the values in a column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row66327457153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a8e3cf7fe4aee4e11b9896aededbd2976">min(col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a815ed53d9bbd4e42b0f74759967bd638">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_aa0295c8a602a4f3491c3bf13563af667">Return the minimum value of a column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row52475606153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_acaf456b069ff4e63a6f0cc1d4cb6c7d3">max(col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_aac4513e8dd9d4ae2aaff48bc01088f86">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a2c94d8c18d694ab28dae0daa8186df90">Return the maximum value of a column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row36621669153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a4c78991b5d4b4fc1a8eba20af88ae368">variance(col), var_pop(col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a369bb57a0e324dbdbc6b3aeb3516a788">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a33a374a6aac64a36b96f39945983eaf4">Return the variance of a numeric column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row66440051153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a6e880ae0bf8443fe8668917d815b3e71">var_samp(col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a2ee50eedc5624e909c767c91093210d4">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a53e456488fcd475e905c8a7f05f34dc6">Return the sample variance of a numeric column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row36033649153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a62f2f78dd9034c6e8243d0ac12fd6efa">stddev_pop(col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_aeb58f765ab944f53ba606d69ffb90fa5">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a8433e209b48748e4868b881a863a88db">Return the deviation of a numeric column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row49642708153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_aad266475cdb44b6cac8508a1212a66bf">stddev_samp(col)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a61dd23f951864a22a288cc6f0ec843d4">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a00ff2dd249084a90ab01a1b25f849f4f">Return the sample deviation of a numeric column.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row54107613153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_ac8ecfeae59dd4143b5b8467e59d4cc37">covar_pop(col1, col2)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a7a2db4c38fd8424a8136c207234cb983">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a3f7abf35fbed4916965961fc924f2862">Return the covariance of a pair of numeric columns.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row38120274153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a291f44b3d9f3417294abc714ee7da922">covar_samp(col1, col2)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a542304d1414042e2b1b531d6f05d290a">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_ac26c829c4e5f43039ae526fc25b80885">Return the sample covariance of a pair of numeric columns.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row17267522153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a2319144eb1354f319af60a8523631825">corr(col1, col2)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a119fac11bb4548fa9e9af01a725cb2f8">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a699d054b87be4c848217d7c740c63b04">Return the coefficient of correlation of a pair of numeric columns.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row16904132153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a81e90e3c83224360b3442c628075af34">percentile(BIGINT col, p)</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a95174e050baa417fac900475f6be3ba4">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a2e37c84511dd46e8b760cac4692f6861">Return the exact pth percentile of a column. <strong id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_b4121176493929">p</strong> must be between 0 and 1. Otherwise, this function returns null. This function does not work with floating point types.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_row27118699153322"><td class="cellrowborder" valign="top" width="24.310000000000002%" headers="mcps1.3.2.2.4.1.1 "><p id="dli_08_0068__en-us_topic_0093946736_a49a14482a54b4d65a495f12d0351a621">percentile_approx(DOUBLE col, p [, B])</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="18.77%" headers="mcps1.3.2.2.4.1.2 "><p id="dli_08_0068__en-us_topic_0093946736_a7b952e13ed1d4abb8fe3152c92efcf70">DOUBLE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="56.92%" headers="mcps1.3.2.2.4.1.3 "><p id="dli_08_0068__en-us_topic_0093946736_a28bc5280f9b24b499962c987ef28c045">Return an approximate pth percentile of a numeric column (including floating point types) in a group. <strong id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_b998313415339">p</strong> must be between 0 and 1. <strong id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_b4673355793929">B</strong> controls approximation accuracy. Higher values of <strong id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_b1794883793929">B</strong> mean better approximations, and the default value is 10,000. When the number of distinct values in the numeric column is smaller than <strong id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_en-us_topic_0039551487_b2732180993929">B</strong>, an exact percentile value is returned.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="note" id="dli_08_0068__en-us_topic_0093946736_en-us_topic_0047959803_note31875846155118"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dli_08_0068__en-us_topic_0093946736_ade1221aa5c85403da39a70035d681cef">Functions such as var_pop, stddev_pop, var_samp, stddev_samp, covar_pop, covar_samp, corr, and percentile_approx, do not support non-numeral data types, such as TimeStamp.</p>
|
|
</div></div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0064.html">Built-in Functions</a></div>
|
|
</div>
|
|
</div>
|
|
|