1.分组查询 按照指定字段进行分组,字段中数据相等的分为一组 group by 列名 [having 条件表达式] [with rollup]
列名:按照指定字段的值进行分组
having 条件表达式:用来过滤分组后的数据
with rollup:在所有记录的最后加上一条记录,显示select查询时聚合函数的统计和计算结果 2.group by使用 select gender from students group by gender; select name, gender from students group by name, gender; 3.group by + group_concat() group_concat(字段名):统计每个分组指定字段的信息集合,每个信息之间使用逗号进行分割。 select gender, group_concat(name) from students group by gender; e.g. select gender, group_concat(name) from students group by gender; select gender, count() form students group by gender ; select gender, avg(age) from students group by gender; select gender, count() from students group by gender having count(*) >2; select gender, sum(age) from students group by gender;