where子句中的and和or的影響

2021-09-22 16:50:42 字數 559 閱讀 7578

and 和 or 的執行條件

select *

from emp

where deptno = 10

or comm is not null

or sal <= 2000 and deptno = 20;

在這個例項中where子句找到了如下的資料:

or將前後的關係並列,有or的出現,使where子句進行分段。效果相當於:

select *

from emp

where deptno = 10

or comm is not null

or (sal <= 2000 and deptno = 20);

如果將上述的**進行修改:

select *

from emp

where deptno = 10

and comm is not null

or sal <= 2000 and deptno = 20;

where子句找到如下資料:

關於where子句中的子查詢語法說明

首先說一句,大神就不用看了。先看乙個sql語句 select distinct name from user u1 where select count from user u2 where u1.name u2.name 3 這句話是選出user表中name欄位相同的名字出現三次以上的name。這...

Oracle之Where子句中常用的運算子

sql select ename,job,sal,comm from emp where job salesman or job president and sal 1500 ename job sal comm allen salesman 1600.00 300.00 ward salesman...

在WHERE子句中引用取別名的列

問題 前面已經使用了別名為查詢提供更有意義的列名,而且也使用where子句將一些資料排除掉,然而,我們還想在where子句中引用別名。select sal as salary,comm as commission from emp where salary 5000 解決方案 將查詢作為內聯檢視就可...