什么是 SQL 的 Aggregate Functions(聚合函数)

它是⼀个返回单个值的数学函数。

SQL中的聚合函数是:

  • AVG()——返回平均值
  • COUNT()——返回⾏数
  • MAX()——返回最⼤值
  • MIN()——返回最⼩值
  • ROUND()——基于⼗进制规范,此函数对数字字段进⾏舍⼊
  • SUM()——返回总和

MySQL 的聚合函数,请参考下官方的参考手册:https://dev.mysql.com/doc/refman/8.4/en/aggregate-functions.html

Name Description
AVG() Return the average value of the argument
BIT_AND() Return bitwise AND
BIT_OR() Return bitwise OR
BIT_XOR() Return bitwise XOR
COUNT() Return a count of the number of rows returned
COUNT(DISTINCT) Return the count of a number of different values
GROUP_CONCAT() Return a concatenated string
JSON_ARRAYAGG() Return result set as a single JSON array
JSON_OBJECTAGG() Return result set as a single JSON object
MAX() Return the maximum value
MIN() Return the minimum value
STD() Return the population standard deviation
STDDEV() Return the population standard deviation
STDDEV_POP() Return the population standard deviation
STDDEV_SAMP() Return the sample standard deviation
SUM() Return the sum
VAR_POP() Return the population standard variance
VAR_SAMP() Return the sample variance
VARIANCE() Return the population standard variance

不同版本的函数不一样,这个 8.4 的版本。

postgresql 的聚合函数功能多。

参考:PostgreSQL: Documentation: 9.5: Aggregate Functions

其实也就是一类函数的总称。

日常来说,count 天天用。