和groupby配合使用的Mysql聚合函數是最重要的Mysql函數之一。
除非特殊說明,Mysql聚合函數均忽略 null 值的記錄。
除非特殊說明,Mysql聚合函數均在沒有匹配記錄(記錄集爲空)的情況下均返回 null 值。
如果在沒有使用group by的語句中使用Mysql聚合函數,相當於對所有的行進行分組。
Aggregate (GROUP BY) Functions
Name |
Description |
Return the average value of the argument |
|
Return bitwise and |
|
Return bitwise or |
|
BIT_XOR()(v4.1.1) |
Return bitwise xor |
Return the count of a number of different values |
|
Return a count of the number of rows returned |
|
GROUP_CONCAT()(v4.1) |
Return a concatenated string |
Return the maximum value |
|
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 |
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值。