请教大神,为什么方法一中还能出现950的sal,前面不是已经有“sal>1000”的条件了吗,能不能帮我分析一下这两种方法的区别,感激!方法一:
SQL> select ename ,sal ,deptno from emp where sal>1000 and deptno=20 or deptno=3
0;ENAME SAL DEPTNO
---------- ---------- ----------
ALLEN 1600 30
WARD 1250 30
JONES 2975 20
MARTIN 1250 30
BLAKE 2850 30
SCOTT 3000 20
TURNER 1500 30
ADAMS 1100 20
JAMES 950 30
FORD 3000 20已选择10行。方法二:
SQL> select ename ,sal,deptno from emp where sal>1000 and( deptno=20 or deptno=3
0);ENAME SAL DEPTNO
---------- ---------- ----------
ALLEN 1600 30
WARD 1250 30
JONES 2975 20
MARTIN 1250 30
BLAKE 2850 30
SCOTT 3000 20
TURNER 1500 30
ADAMS 1100 20
FORD 3000 20已选择9行。oracleSQLselect
SQL> select ename ,sal ,deptno from emp where sal>1000 and deptno=20 or deptno=3
0;ENAME SAL DEPTNO
---------- ---------- ----------
ALLEN 1600 30
WARD 1250 30
JONES 2975 20
MARTIN 1250 30
BLAKE 2850 30
SCOTT 3000 20
TURNER 1500 30
ADAMS 1100 20
JAMES 950 30
FORD 3000 20已选择10行。方法二:
SQL> select ename ,sal,deptno from emp where sal>1000 and( deptno=20 or deptno=3
0);ENAME SAL DEPTNO
---------- ---------- ----------
ALLEN 1600 30
WARD 1250 30
JONES 2975 20
MARTIN 1250 30
BLAKE 2850 30
SCOTT 3000 20
TURNER 1500 30
ADAMS 1100 20
FORD 3000 20已选择9行。oracleSQLselect
解决方案 »
- oracle实例startup 时出错
- oracle goldengate
- 存储过程中表字段的类型不支持
- oracle 9i 多行转换成1行
- 如何取表中第一行的时与最后一个时间相减,急,请教专家
- oracle tablespace 问题
- 这个接口不知俱体怎么样实现?(请各位高手帮我指点指点)(抱歉,我的分用完了)
- 怎么修改windows2000一次I/O缓冲的大小.
- 如何改变创建数据库的文件存储的默认位置
- alter table map_tbl rename column recep_id to recp_id这个怎么不行啊
- 关于ORACLE 10G中运行CDC的问题!
- 求数据仓库设计 需求分析说明书、概要设计等参考文档。
出现这样的问题时,做好用 () 来约束,易于理解,又比较高的可读性
这个就相当于
select ename ,sal ,deptno from emp where (sal>1000 and deptno=20) or (deptno=3)虽然950那条记录不满足(sal>1000 and deptno=20),但是它满足(deptno=3),所以也能查出来了、
相当于 (sal>1000 and deptno=20) or (deptno=30)
select ename ,sal ,deptno from emp where sal>1000 and deptno=20 or deptno=3
这个就相当于
select ename ,sal ,deptno from emp where (sal>1000 and deptno=20) or (deptno=3)虽然950那条记录不满足(sal>1000 and deptno=20),但是它满足(deptno=3),所以也能查出来了第二种情况sal>1000 and (deptno=20 or deptno=3) 先满足了扩好内的在去判断sal>1000的情况,由于是and的关系deptno=20 或者3的就被过滤掉了.
0);
select ename ,sal,deptno from emp where sal>1000 and( deptno=20 or deptno=3);
出现这样的问题,是and和or优先级的问题,and优于or,所以第一个sql和
select ename ,sal ,deptno from emp where (sal>1000 and deptno=20) or deptno=3;
所以会出现了sal<1000的情况。