分组查询的作用是将查询的结果按指定字段分组,字段中数值相等的为一组。
分组以后可以配合count()、agv()、sum()、max()等聚合函数使用。
group by 列名 [having表达式][with rollup]
having表达式:用来过滤分组后的数据
with rollup:在所记录后加一条,显示select查询聚合的结果
select gender , group_concat(name) from student grop by gender;
根据gender,分组name集合,分组显示name。
select gender , count(name) from student grop by gender with rollup;
根据gender,分组name集合,统计name的个数。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。