码迷,mamicode.com
首页 > 数据库 > 详细

oracle where与having

时间:2014-12-23 22:25:22      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:

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

 

oracle where与having

标签:

原文地址:http://www.cnblogs.com/liuwt365/p/4181244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!