Oracle之where 和having中的区别-yellowcong
来源:互联网 发布:sql执行视图命令 编辑:程序博客网 时间:2024/06/10 22:19
今天做项目的时候,突然看到了having这个玩意,就查了一下,having是在group by后面,然后对组添加判断条件的, 它们的相似之处就是定义搜索条件,不同之处是where子句为单个筛选而having子句与组有关,而不是与单个的行有关。
having的使用场景
当我们查询员工的工资的这种聚合函数,然后需要在group后,判断数据
select deptno,sum(sal) from emp group by deptno having sum(sal)>10000;
having和where的区别
在查询过程中聚合语句(sum,min,max,avg,count)要比having子句优先执行,简单的理解为只有有了统计结果后我才能执行筛选啊。where子句在查询过程中执行优先级别优先于聚合语(sum,min,max,avg,count),因为它是一句一句筛选的。HAVING子句可以让我们筛选成组后的对各组数据筛选。而WHERE子句在聚合前先筛选记录。如:现在我们想要部门号不等于10的部门并且工资总和大于8000的部门编号?
我们这样分析:通过where子句筛选出部门编号不为10的部门,然后在对部门工资进行统计,然后再使用having子句对统计结果进行筛选。
select deptno, sum(sal) from emp where deptno != '10' group by deptnohaving sum(sal) > 8000;
阅读全文
0 0
- Oracle之where 和having中的区别-yellowcong
- Oracle中where子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- oracle中where子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 6-oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 在oracle中where 子句和having子句中的区别
- 【having子句】在oracle中where 子句和having子句中的区别
- oracle where 和having从句区别
- oracle 之where子句和having子句
- oracle-where和having
- java中读取properties文件内容五种方式
- 队列-queue详解
- Miller_Rabin素性测试学习小结
- hdu 1522 Marriage is Stable(稳定婚姻问题)
- HDU5543 Pick The Sticks [背包dp变形]
- Oracle之where 和having中的区别-yellowcong
- 【Ambari】2.5.1.0.0汉化、构建和安装
- 什么是α测试?什么是β测试?
- vm桥接设置都正确时,如果还无法上网请关闭本机防火墙设置
- javascript面向对象——prototype属性(原型属性)
- Swoole笔记(五)
- Android双向表格可滑动可双向适配
- osmf grindPlayer的各种api。
- 缓冲区分析—ArcGIS API for JavaScript