功能:用作统计使用,又称为聚合函数或统计函数或组函数
分类:sum 求和、 avg 平均值、max 最大值、min 最小值、count 计数个数
一般和group by后面的字段搭配
可以和distinct(去重)搭配
select
COUNT(distinct salary),count(salary)
from
employees;
count函数
select
COUNT(distinct salary),count(salary)
from
employees;
select
COUNT(*) //计算主键不为null值的行数
from
employees;
select
COUNT(1)
from
employees;
效率:
MYISAM存储引擎下COUNT()的效率高
INNODB存储引擎下COUNT()和COUNT(1)效率差不多,比COUNT(字段)高一些
DATEDIFF()求两个日期相差的天数
select
DATEDIFF(now(),'1999-04-07')