--分组查询 GROUP BY: 在对数据进行分组的时候,select后面必须是分组字段或者聚合函数
select * from student;
select class from student group by class;

select class, avg(age) from student group by class;

select gender, avg(age) avgAge from student group by gender;

--HAVING条件查询: WHERE 是取数据表中查询符合条件的数据返回结果集,HAVING是取结果集中查询符合条件的数据,可以对分组之后查询到的结果进行筛选
select class , avg(age) from student group by class;

select class , avg(age) from student group by class where avg(age) <= 19 ; --报错
select class , avg(age) avg from student group by class having avg(age) <= 19 ; --正确 在结果集中筛选

select class,avg(age) from student group by class;