溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

SQLServer中有哪些比較運算符

發(fā)布時間:2021-08-06 11:08:55 來源:億速云 閱讀:111 作者:Leah 欄目:數(shù)據(jù)庫

SQLServer中有哪些比較運算符,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

他們作用于比較運算符和子查詢之間,作用類似Exists、not exists、in、not in以及其他邏輯意義,這些語法同樣被SQLServer2000支持但是很少看到有人用它們。復(fù)制代碼 代碼如下: set nocount on use tempdb go if (object_id ('t1' ) is not null ) drop table t1 create table t1 (n int ) insert into t1 select 2 union select 3 if (object_id ('t2' ) is not null ) drop table t2 create table t2 (n int ) insert into t2 select 1 union select 2 union select 3 union select 4 select * from t2 where n> all (select n from t1 ) --4 select * from t2 where n> any (select n from t1 ) --3,4 --select * from t2 where n>some(select n from t1) --3,4 select * from t2 where n= all (select n from t1 ) --無數(shù)據(jù) select * from t2 where n= any (select n from t1 ) --2,3 --select * from t2 where n=some(select n from t1) --2,3 select * from t2 where n< all (select n from t1 ) --1 select * from t2 where n< any (select n from t1 ) --1,2 --select * from t2 where n<some(select n from t1) --1,2 select * from t2 where n<> all (select n from t1 ) --1,4 select * from t2 where n<> any (select n from t1 ) --1,2,3,4 --select * from t2 where n<>some(select n from t1)--1,2,3,4 set nocount off

注意,如果t1中包含null數(shù)據(jù),那么所有All相關(guān)的比較運算將不會返回任何結(jié)果,原因就不用多解釋了。而因為t1和t2表的null的存在他們和not exists之類的比較符會有一些區(qū)別。 比如下面兩句 select * from t2 a where not exists(select 1 from t1 where n>=a.n) select * from t2 where n >all(select n from t1) 他們邏輯上意義很像但是對于null的處理卻是恰恰相反,第一句會忽略子查詢的null而把t2的null同時查出來,第二句卻是忽略了t2的null同時會因為t1中的null而無法查詢到數(shù)據(jù)。

看完上述內(nèi)容,你們掌握SQLServer中有哪些比較運算符的方法了嗎?如果還想學到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI