您的位置:首页 > 数据库 > MySQL

Mysql聚合函数简介

2013-11-19 08:52 260 查看
和groupby配合使用的Mysql聚合函数是最重要的Mysql函数之一。
 
除非特殊说明,Mysql聚合函数均忽略 null 值的记录。
除非特殊说明,Mysql聚合函数均在没有匹配记录(记录集为空)的情况下均返回 null 值。
如果在没有使用group by的语句中使用Mysql聚合函数,相当于对所有的行进行分组。

 
Aggregate (GROUP BY) Functions
Name
Description
AVG()
Return the average value of the argument
BIT_AND()
Return bitwise and
BIT_OR()
Return bitwise or
BIT_XOR()(v4.1.1)
Return bitwise xor
COUNT(DISTINCT)
Return the count of a number of different values
COUNT()
Return a count of the number of rows returned
GROUP_CONCAT()(v4.1)
Return a concatenated string
MAX()
Return the maximum value
MIN()
Return the minimum value
STDDEV_POP()(v5.0.3) STDDEV() 
STD()
Return the population standard deviation
STDDEV_SAMP()(v5.0.3)
Return the sample standard deviation
SUM()
Return the sum
VAR_POP()(v5.0.3)

VARIANCE()(v4.1)
Return the population standard variance
VAR_SAMP()(v5.0.3)
Return the sample variance
bit_and() 如果没有行返回,则为 最大的unsigned bigint整数:18446744073709551615
bit_or()、bit_xor() 如果没有行返回,则为 0
count(*)返回所有行的数据,包括null,如果没有行返回,则为 0
count(expr)返回所有非null的数据,如果没有行返回,则为 0
count(distinct expr)返回所有非null的不同数据,如果没有行返回,则为 0;和sql标准不兼容,标准sql返回所有不同的数据的行数,包括null值。
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql 数据库