group by用于将表中数据划分为若干个组,group by后面用于指定分组的依据
1、
#group by 查询语句中select 聚合函数,分组字段
select name, count(id) from student;#此时不合法
select name, count(id) from student group by name;#将student表学生按照name分组,然后统计每组中的人数
2、
#查询哪个姓名重名
select name, count(id) from student group by name having count(id)>1
3、where 不能跟聚合函数
4、如果select语句中含有where、order by,group by和having,他们的先后顺序为:
where group by having order by