↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

受支持版本: 当前版本 (18) / 17 / 16 / 15 / 14
测试与开发版本: 19 / devel
不受支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
历史版本PostgreSQL 7.3 已于 2007 年 11 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本。

6.14. 聚合函数 #

聚合函数从一组输入值中计算出一个单一的 结果值。表 6.33 展示了内置的聚合 函数。聚合函数的特殊语法 考虑在第 1.2.5 节中解释。 更多介绍信息请参阅 PostgreSQL 7.3.21 教程。

表 6.33. 聚合函数

函数 参数类型 返回类型 描述  
avg(expression) smallint, integer, bigint, real, double precision, numeric, or interval. 整数类型参数为numeric,浮点参数为double precision,否则与参数数据类型相同 所有输入值的平均值(算术平均)  
count(*)   bigint 输入值的数目  
count(expression) 任意类型 bigint expression 的值不为 null 的输入行数  
max(expression) 任意数字、字符串或日期/时间类型 与参数类型相同 expression 在所有输入值中的最大 值  
min(expression) 任意数字、字符串或日期/时间类型 与参数类型相同 expression 在所有输入值中的最小 值  
stddev(expression) smallint, integer, bigint, real, double precision, or numeric. 浮点参数为 double precision, 否则为 numeric。 输入值的样本标准差  
sum(expression) smallint, integer, bigint, real, double precision, numeric, or interval smallint或integer参数为bigint,bigint参数为numeric,浮点参数为double precision,否则与参数数据类型相同 expression 在所有输入值上的总和  
variance(expression) smallint, integer, bigint, real, double precision, or numeric. 浮点参数为 double precision, 否则为 numeric。 输入值的样本方差(样本标准差的平方)  

应当注意,除了 count 之外, 这些函数在没有选中任何行时都返回空值。特别地, 没有行时 sum 返回空值,而不是人们可能预期的零。 必要时可以使用 coalesce 函数把空值替换为零。

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。