where与having可以过滤,一般来说尽量使用where ,但是如果过滤条件中有组函数,只能使用having
1 SQL> select deptno,avg(sal) 2 2 from emp 3 3 where deptno=10 4 4 group by deptno; 5 6 DEPTNO AVG(SAL) 7 ------ ---------- 8 10 2950 9 10 SQL> 11 SQL> select deptno,avg(sal) 12 2 from emp 13 3 where avg(sal)>2000 14 4 group by deptno; 15 16 select deptno,avg(sal) 17 from emp 18 where avg(sal)>2000 19 group by deptno 20 21 ORA-00934: 此处不允许使用分组函数 22 23 SQL> 24 SQL> select deptno,avg(sal) 25 2 from emp 26 3 group by deptno 27 4 having avg(sal)>2000; 28 29 DEPTNO AVG(SAL) 30 ------ ---------- 31 20 2258.33333 32 10 2950