按照deptno分组之后,每个组再按照job进行细分,然后统计每个job小分组的数量
select deptno,job,count(*) from emp group by deptno,job order by deptno,count(*)
先按照deptno job将整张表进行分组,然后然后筛选出count>1的
having的优先级比较低,可以做到先分组后筛选
where优先级要比group高,用多行函数的时候不能用where,否则逻辑错误
select deptno,job,count(*) from emp group by deptno,job having count(*)>1
当可以先筛选再分组时where和group都可以用,但是where的效率要高
select deptno,job,count(*) from emp where deptno>10 group by deptno,job order by deptno