聚合函数
函数的分类
单行函数
每一行返回一个值
多行函数
多行返回一个值
例子:
select LOWER(item_name) from dbo.d_check_applyinfo
聚合函数的分类
max() 最大值
min() 最小值
avg() 平均值
count() 求个数
count(*)
返回表中所有的记录的个数
select COUNT(*) from dbo.d_check_applyinfo
count(字段名)
返回字段值非空的记录的个数,重复的记录也会被当做有效
select COUNT(item_name) from dbo.d_check_applyinfo
count(distinct 字段名)
返回字段不重复并且非空的记录个数
select COUNT(distinct item_name) from dbo.d_check_applyinfo
select MAX(item_name) as “名字” from dbo.d_check_applyinfo
select COUNT(*) from dbo.d_check_applyinfo
–返回表所有记录的个数
select COUNT(item_name) from dbo.d_check_applyinfo
–返回值说明重复记录也被搜索出来了
select COUNT(distinct item_name) from dbo.d_check_applyinfo
–返回值统计列不重复的结果
注意的问题:
select MAX(item_name) as “最大值”,MIN(item_name) as “最小值”,COUNT(*) as “总个数”
from dbo.d_check_applyinfo
select MAX(item_name),LOWER(item_name) from dbo.d_check_applyinfo
–error 单行函数与多行函数错误