--按照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 的顺序进行

 

posted on 2018-01-28 08:59  奋斗中的菜鸟程序猿  阅读(374)  评论(0编辑  收藏  举报