oracle where与having

时间:2023-03-09 06:25:05
oracle where与having

where与having可以过滤,一般来说尽量使用where ,但是如果过滤条件中有组函数,只能使用having

 SQL> select deptno,avg(sal)
2 from emp
3 where deptno=10
4 group by deptno; DEPTNO AVG(SAL)
------ ----------
10 2950 SQL>
SQL> select deptno,avg(sal)
2 from emp
3 where avg(sal)>2000
4 group by deptno; select deptno,avg(sal)
from emp
where avg(sal)>2000
group by deptno ORA-00934: 此处不允许使用分组函数 SQL>
SQL> select deptno,avg(sal)
2 from emp
3 group by deptno
4 having avg(sal)>2000; DEPTNO AVG(SAL)
------ ----------
20 2258.33333
10 2950