邏輯運算子的優先順序 APP

2021-10-04 07:25:46 字數 726 閱讀 5298

目錄

環境文件用途

詳細資訊

環境系統平台:n/a

版本:5.6.4

文件用途

本文件闡述了邏輯運算子的順序。

詳細資訊

通過使用邏輯運算子(and、or、not),可以將多個查詢條件進行組合,通過 not 運算子可以生成「不是~」這樣的查詢條件,但是邏輯運算子本身也存在執行的先後順序,如果不能正確理解會導致寫出的sql不能得到正確的執行結果。

not 運算子優先順序高於and 運算子,and 運算子的優先順序高於 or 運算子。想要優先執行 or 運算子時可以使用括號。

建立測試表並插入測試資料:

create table  op (a int,b int,c int); insert into op values(1,1,1);

insert into op values(2,2,2);

insert into op values(3,3,3);

insert into op values(1,2,2);

insert into op values(3,2);

shop=# select * from op;

a | b | c

1 | 1 | 1

2 | 2 | 2

3 | 3 | 3

1 | 2 | 2

3 | 2 |

(5 行記錄)

更多詳細資訊請登入【瀚高技術支援平台】檢視 

sql 邏輯運算子 優先順序

select from tl documentation where storehouse id 2 orcustomer id 2 andproduct id 20 order byid desc limit0,30 以下列表顯示了操作符優先順序的由低到高的順序。排列在同一行的操作符具有相同的優先...

oracle邏輯運算子優先順序

oracle中邏輯運算子 not,and,or 及其優先順序 2008 12 05 15 06 oracle的邏輯運算子也是用在sql 語句中必不可少的因素,一共有三個 邏輯運算子 意義and 雙值運算子,如果左右兩個條件都為真,則得到的值就為真 or雙值運算子,只要左右兩個條件有乙個為真,則得到的...

sql 邏輯運算子 優先順序

select from tl documentation where storehouse id 2 orcustomer id 2 andproduct id 20 order byid desc limit0,30以下列表顯示了操作符優先順序的由低到高的順序。排列在同一行的操作符具有相同的優先順...