--聚合函数和分组函数
--1。统计学生的人数 count(字段名称) 统计该数列中不为空的记录条数。
select count(*) 人数
from t_student;
--count(*)是统计所有行 count(1)是常量表达式,给多一行设置为 1 计算1的个数
--2.其他常用的统计函数 最大值 最小值 求和 四舍五入 平均值
select count(1),max(age),min(age),sum(age),round(avg(age))
from t_student;
--分组函数 group by
--1. 不和聚合函数一起使用,作用和distinct是一样的,可以去掉重复数据
select * from emp;
select deptno from emp group by deptno;
select distinct deptno from emp;
--2. 和聚合函数一块使用的场景
--分组后的数据中我们不能直接出现非分组的字段
--a.统计出学生表中男生和女生的人数
select gender,count(gender)
from t_student
group by gender;