激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|數(shù)據(jù)庫技術(shù)|

服務(wù)器之家 - 數(shù)據(jù)庫 - Sql Server - 被遺忘的SQLServer比較運(yùn)算符謂詞

被遺忘的SQLServer比較運(yùn)算符謂詞

2019-11-14 17:23mssql教程網(wǎng) Sql Server

SQLServer中有三個(gè)關(guān)鍵字可以修改比較運(yùn)算符:All、Any和Some,其中Some和Any等價(jià)。

官方的參考文檔 
http://technet.microsoft.com/zh-cn/library/ms187074%28SQL.90%29.aspx 
他們作用于比較運(yù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)的比較運(yùn)算將不會返回任何結(jié)果,原因就不用多解釋了。而因?yàn)閠1和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同時(shí)查出來,第二句卻是忽略了t2的null同時(shí)會因?yàn)閠1中的null而無法查詢到數(shù)據(jù)。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩视 | 一级爱片 | 欧美成人自拍 | 成人在线免费视频播放 | 日韩av影片在线观看 | 日韩视频在线视频 | 91精品观看91久久久久久国产 | 精品国产网站 | 综合网日日天干夜夜久久 | 一级成人欧美一区在线观看 | 亚洲成人福利网站 | 国产在线精品一区二区夜色 | av中文一区| 精品国产乱码一区二区三区四区 | 亚洲精品久久久久久久久久久 | 羞羞的视频免费 | 色阁阁69婷婷 | 九九热精品视频在线 | 免费看国产 | 成人免费乱码大片a毛片视频网站 | 99国产精品国产免费观看 | 国产精品久久久不卡 | 在线看一区二区三区 | 日本在线国产 | 国产精品免费一区二区三区都可以 | 免费人成在线播放 | 国产剧情在线观看一区二区 | 蜜桃一本色道久久综合亚洲精品冫 | 综合在线一区 | 欧美日韩亚洲在线 | 国产精品一区久久久久 | 久久恋 | 国产成人精品无人区一区 | 玩偶姐姐 在线观看 | 久久久久久99 | 国产美女自拍av | 久久99国产伦子精品免费 | 九九福利视频 | 毛片在线免费 | 国产91精品久久久久久 | 久久毛片|