本文共 334 字,大约阅读时间需要 1 分钟。
之前都是单条记录数据筛选分析,分组就可以对一组记录数据进行筛选分析。
group by 字段
用来对数据进行分组
-- 每个部门有几个员工select deptno,count(1) from emp group by deptno
运行结果 |
---|
Tips:
group by 字段
关键字不能出现在select
中having
关键字是组过滤
where:过滤行信息,不能使用组顾虑
having:过滤组,可以使用组函数
-- 每个部门平均工资高于2000的select deptno,count(1) from emp group by deptno having avg(sal) > 2000
运行结果 |
---|
转载地址:http://ncsnb.baihongyu.com/