ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] # <span style="font-size:15px">**通用聚合函数**</span> <table border="0"> <tbody> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">函数</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">参数类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">返回类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">描述</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">示例</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">结果</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">array_agg(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">任意非数组类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">参数类型的数组</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">将入参包括NULL连接成一个数组</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select array_agg(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">{1,2,3}</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">array_agg(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">任意数组类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">入参数据类型</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">将入参数组连接成更高维度的数组,输入的数组必须是相同</span><span style="font-family: &quot;courier new&quot;, courier">的维度,且不允许是空或NULL</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">select array_agg(array['b','c','a']);</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">&nbsp;{{b,c,a}}</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">avg(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span class="Apple-tab-span" style="font-family: &quot;courier new&quot;, courier"> smallint, int, bigint, real, double precision, numeric, or interval</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">整形返回numeric,浮点型返回double precision,其他和入参类型相同</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">平均值</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select avg(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">2.0000000000000000</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">bit_and(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="TYPE">smallint</tt>,&nbsp;<tt class="TYPE">int</tt>,&nbsp;<tt class="TYPE">bigint</tt>, or&nbsp;<tt class="TYPE">bit</tt></span></td> <td><span style="font-family: &quot;courier new&quot;, courier">和入参类型相同</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">所有非NULL输入值的按位与,如果全为NULL则返回NULL</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select bit_and(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">0</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">bit_or(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="TYPE">smallint</tt>,&nbsp;<tt class="TYPE">int</tt>,&nbsp;<tt class="TYPE">bigint</tt>, or&nbsp;<tt class="TYPE">bit</tt></span></td> <td><span style="font-family: &quot;courier new&quot;, courier">和入参类型相同</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">所有非NULL输入值的按位或,如果全为NULL则返回NULL</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select bit_or(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">3</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">bool_and(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bool</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bool</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">如果输入全是true则返回true,否则为false</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select bool_or(id::bool) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">t</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">bool_or(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bool</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bool</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">如果输入至少一个true,则返回true,否则返回false</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select bool_or((id-1)::bool) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">t</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">count(*)</span></td> <td>&nbsp;</td> <td><span style="font-family: &quot;courier new&quot;, courier">bigint</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">输入行数</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select count(*) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">3</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">count(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">any</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bigint</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">输入行中非NULL的行数</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select count(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">3</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">every(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bool</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bool</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">功能同bool_and</span></td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">json_agg(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">any</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">json</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">将输入聚合成一个json数组</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select json_agg(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">[1, 2, 3]</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">jsonb_agg(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">any</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">jsonb</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">将输入聚合成一个json数组</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select jsonb_agg(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">[1, 2, 3]</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">json_object_agg(<tt class="REPLACEABLE c3">name</tt>,<tt class="REPLACEABLE c3">value</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">(any, any)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">json</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">将输入组成一个key/value对的json对象</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select json_object_agg('a','one');</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">{ "a" : "one" }</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">jsonb_object_agg(<tt class="REPLACEABLE c3">name</tt>,<tt class="REPLACEABLE c3">value</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">(any, any)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">jsonb</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">将输入组成一个key/value对的json对象</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select jsonb_object_agg('a','one');</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">{"a": "one"}</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">max(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td>&nbsp;</td> <td>&nbsp;</td> <td><span style="font-family: &quot;courier new&quot;, courier">输入最大值</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">select max(id) from tbl_test;</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">3</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">min(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td>&nbsp;</td> <td>&nbsp;</td> <td><span style="font-family: &quot;courier new&quot;, courier">输入最小值</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select min(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">string_agg(<tt class="REPLACEABLE c3">expression</tt>,<tt class="REPLACEABLE c3">delimiter</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">(<tt class="TYPE">text</tt>,&nbsp;<tt class="TYPE">text</tt>) or (<tt class="TYPE">bytea</tt>,&nbsp;<tt class="TYPE">bytea</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">同参数类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">将输入使用delimiter连接成一个text</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select string_agg(name,',') from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">&nbsp;张三,李四,王五</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">sum(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="TYPE">smallint</tt>,&nbsp;<tt class="TYPE">int</tt>,&nbsp;<tt class="TYPE">bigint</tt>,&nbsp;<tt class="TYPE">real</tt>,&nbsp;<tt class="TYPE">double precision</tt>,&nbsp;<tt class="TYPE">numeric</tt>,&nbsp;<tt class="TYPE">interval</tt>, or&nbsp;<tt class="TYPE">money</tt></span></td> <td>&nbsp;</td> <td><span style="font-family: &quot;courier new&quot;, courier">输入和</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select sum(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">6</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">xmlagg(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">xml</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">xml</span></td> <td>&nbsp;</td> <td><span style="font-family: &quot;courier new&quot;, courier">请参考xml类型及其函数</span></td> <td>&nbsp;</td> </tr> </tbody> </table> # <span style="font-size:15px">**统计聚合函数**</span> <table border="0"> <tbody> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">函数</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">参数类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">返回类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">描述</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">示例</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">结果</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">corr(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">相关系数</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select corr(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">covar_pop(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">总体协方差</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select covar_pop(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">0.666666666666667</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">covar_samp(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">样本协方差</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select covar_samp(id,id1) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">0</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_avgx(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">自变量平均值(sum(X)/N)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_avgx(id,id1) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_avgy(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">因变量平均值(sum(Y)/N)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_avgy(id,id1) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">2</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_count(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">bigint</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">两个参数都不为NULL的行数</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">&nbsp;select regr_count(id,id1) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">3</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_intercept(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">根据所有输入点(X,Y)利用最小二乘法计算一个线性方程式。然后返回该直线的Y轴截距</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_intercept(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">0</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_r2(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">相关系数平方</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_r2(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_slope(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">根据所有输入点(X,Y)利用最小二乘法计算一个线性方程式。然后返回该直线的斜率</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_slope(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_sxx(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="LITERAL">sum(<tt class="REPLACEABLE c3">X</tt>^2) - sum(<tt class="REPLACEABLE c3">X</tt>)^2/<tt class="REPLACEABLE c3">N</tt></tt>&nbsp;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_sxx(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">2</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_sxy(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="LITERAL">sum(<tt class="REPLACEABLE c3">X</tt>*<tt class="REPLACEABLE c3">Y</tt>) - sum(<tt class="REPLACEABLE c3">X</tt>) * sum(<tt class="REPLACEABLE c3">Y</tt>)/<tt class="REPLACEABLE c3">N</tt></tt>&nbsp;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_sxy(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">2</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">regr_syy(<tt class="REPLACEABLE c3">Y</tt>,&nbsp;<tt class="REPLACEABLE c3">X</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="LITERAL">sum(<tt class="REPLACEABLE c3">Y</tt>^2) - sum(<tt class="REPLACEABLE c3">Y</tt>)^2/<tt class="REPLACEABLE c3">N</tt></tt>&nbsp;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select regr_syy(id,id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">2</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">stddev(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">smallint, int, bigint, real,</span></p> <p><span style="font-family: &quot;courier new&quot;, courier"> double precision, or numeric</span></p> </td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">double precision for floating-point arguments, </span></p> <p><span style="font-family: &quot;courier new&quot;, courier">otherwise numeric</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">同stddev_samp</span></td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">stddev_pop(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">smallint, int, bigint, real,</span></p> <p><span style="font-family: &quot;courier new&quot;, courier"> double precision, or numeric</span></p> </td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">double precision for floating-point arguments,</span></p> <p><span style="font-family: &quot;courier new&quot;, courier"> otherwise numeric</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">总体标准差</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select stddev_pop(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">0.81649658092772603273</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">stddev_samp(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">smallint, int, bigint, real,</span></p> <p><span style="font-family: &quot;courier new&quot;, courier"> double precision, or numeric</span></p> </td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">double precision for floating-point arguments, </span></p> <p><span style="font-family: &quot;courier new&quot;, courier">otherwise numeric</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">样本标准差</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select stddev_samp(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1.00000000000000000000</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier"><code class="FUNCTION">variance</code>(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">smallint, int, bigint, real, </span></p> <p><span style="font-family: &quot;courier new&quot;, courier">double precision, or numeric</span></p> </td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">double precision for floating-point arguments,</span></p> <p><span style="font-family: &quot;courier new&quot;, courier"> otherwise numeric</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">同var_samp</span></td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier"><code class="FUNCTION">var_pop</code>(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">smallint, int, bigint, real, </span></p> <p><span style="font-family: &quot;courier new&quot;, courier">double precision, or numeric</span></p> </td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">double precision for floating-point arguments, </span></p> <p><span style="font-family: &quot;courier new&quot;, courier">otherwise numeric</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">总体方差</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select var_pop(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">0.66666666666666666667</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier"><code class="FUNCTION">var_samp</code>(<tt class="REPLACEABLE c3">expression</tt>)</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">smallint, int, bigint, real, </span></p> <p><span style="font-family: &quot;courier new&quot;, courier">double precision, or numeric</span></p> </td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">double precision for floating-point arguments, </span></p> <p><span style="font-family: &quot;courier new&quot;, courier">otherwise numeric</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">样本方差</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select var_samp(id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1.00000000000000000000</span></td> </tr> </tbody> # <span style="font-size:15px">**顺序集聚合函数**</span> <table border="0"> <tbody> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">函数</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">直接参数类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">聚合参数类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">返回类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">描述</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">示例</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">结果</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">mode() WITHIN GROUP (ORDER BY<tt class="REPLACEABLE c3">sort_expression</tt>)</span></td> <td>&nbsp;</td> <td><span style="font-family: &quot;courier new&quot;, courier">任意可排序类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">同排序类型</span></td> <td> <p><span style="font-family: &quot;courier new&quot;, courier">返回最频繁的输入值(如果有</span></p> <p><span style="font-family: &quot;courier new&quot;, courier">多个同样频繁的结果,则返回第一个)</span></p> </td> <td><span style="font-family: &quot;courier new&quot;, courier">select mode() within group (order by id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">2</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">percentile_cont(<tt class="REPLACEABLE c3">fraction</tt>) WITHIN GROUP (ORDER BY&nbsp;<tt class="REPLACEABLE c3">sort_expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="TYPE">double precision</tt>or&nbsp;<tt class="TYPE">interval</tt></span></td> <td><span style="font-family: &quot;courier new&quot;, courier">同排序类型</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">continuous percentile: returns a value corresponding to the specified fraction in the ordering, interpolating between adjacent input items if needed</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">select percentile_cont(0.25) WITHIN GROUP (ORDER BY id) from tbl_test;</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">1.75</span></td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">percentile_cont(<tt class="REPLACEABLE c3">fractions</tt>) WITHIN GROUP (ORDER BY&nbsp;<tt class="REPLACEABLE c3">sort_expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision[]</span></td> <td><span style="font-family: &quot;courier new&quot;, courier"><tt class="TYPE">double precision</tt>or&nbsp;<tt class="TYPE">interval</tt></span></td> <td><span style="font-family: &quot;courier new&quot;, courier">array of sort expression's type</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">multiple continuous percentile: returns an array of results matching the shape of the&nbsp;<tt class="LITERAL">fractions</tt>parameter, with each non-null element replaced by the value corresponding to that percentile</span></td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">percentile_disc(<tt class="REPLACEABLE c3">fraction</tt>) WITHIN GROUP (ORDER BY&nbsp;<tt class="REPLACEABLE c3">sort_expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">any sortable type</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">same as sort expression</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">discrete percentile: returns the first input value whose position in the ordering equals or exceeds the specified fraction</span></td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td><span style="font-family: &quot;courier new&quot;, courier">percentile_disc(<tt class="REPLACEABLE c3">fractions</tt>) WITHIN GROUP (ORDER BY&nbsp;<tt class="REPLACEABLE c3">sort_expression</tt>)</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">double precision[]</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">any sortable type</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">array of sort expression's type</span></td> <td><span style="font-family: &quot;courier new&quot;, courier">multiple discrete percentile: returns an array of results matching the shape of the fractions parameter, with each non-null element replaced by the input value corresponding to that percentile</span></td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> </tbody> </table> </table>