--按照deptno进行分组 查看各个deptno中的数量
select deptno,count(deptno) as avg_deptno from emp group by deptno
--过滤分组 根据deptno进行分组,并筛选大于3的deptno
select deptno,count(deptno) as avg_deptno from emp group by deptno having count(*) > 3;
注:having与where非常相似 但是having配合group by使用,where 只是标准的条件查询
--分组和排序
select sal,count(sal) as ad_sal from emp group by sal having count(*) > 0 order by ad_sal,sal desc;
注:排序的优先级按照order by 的顺序进行