group by 和 having 子句
group by 用于对查询的统计。
having 用于限制分组显示结果。
比如:显示每个部门的平均工资和最高工资。
select avg(sal),max(sal),deptno,job from emp group by deptno,job;
select deptno,avg(sal),max(sal) from emp group by deptno having avg(sal) < 2000 ;
group by 和 having 子句
group by 用于对查询的统计。
having 用于限制分组显示结果。
比如:显示每个部门的平均工资和最高工资。
select avg(sal),max(sal),deptno,job from emp group by deptno,job;
select deptno,avg(sal),max(sal) from emp group by deptno having avg(sal) < 2000 ;