group by
用来和聚合函数(cout, sum, max ,min, avg等)联合使用来得到一个或多个列的结果集合.
语法:
select column1,column2……column_n, aggregate_function(expression)
from tables
where predicates
group by column1,column2……column_n
例如: 查询每个学生选了几门课程及每个学生的平均分数
select id, count(course), avg(score)
from student
group by id
having
与group by联合使用,用来过滤由group by语句返回的记录值
例如:查询平均分大于80分的学生记录
select id, count(course), avg(score)
from student
group by id
having avg(score)>=80