一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

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

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

被遺忘的SQLServer比較運算符謂詞

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

SQLServer中有三個關鍵字可以修改比較運算符:All、Any和Some,其中Some和Any等價。

官方的參考文檔 
http://technet.microsoft.com/zh-cn/library/ms187074%28SQL.90%29.aspx 
他們作用于比較運算符和子查詢之間,作用類似Exists、not exists、in、not in以及其他邏輯意義,這些語法同樣被SQLServer2000支持但是很少看到有人用它們。 

復制代碼代碼如下:


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相關的比較運算將不會返回任何結(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ù)。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 四川一级毛片 | 免费在线观看网址大全 | 99精品久久精品一区二区小说 | 美人的淫事[纯hh] | 校园全黄h全肉细节文 | 3d蒂法精品啪啪一区二区免费 | 亚洲国产成人综合 | 99精品视频在线观看re | 特级淫片大乳女子高清视频 | 女性全身裸露无遮挡 | 歪歪视频在线播放无遮挡 | 羲义嫁密着中出交尾gvg794 | 性欧美xxxxxxx另类 | 4444亚洲国产成人精品 | 欧美大陆日韩一区二区三区 | 精品日韩一区 | 美艳教师刘艳第三部166 | 国产精品久久久久久福利 | 四虎永久网址在线观看 | 久久偷拍国2017 | 成品人视频w免费观看w | 国产精品免费_区二区三区观看 | 男人最爱看的网站 | 欧美综合精品一区二区三区 | 四虎影院网站 | 嫩草影院地址一地址二 | 日本一区二区三区四区无限 | 成年人免费在线视频 | 日韩porn | 国产精品青青青高清在线密亚 | 国产馆在线观看免费的 | 亚洲性色永久网址 | 四虎影视入口 | 精品女同一区二区三区免费站 | 久草热8精品视频在线观看 久草草在线视视频 | 污小说免费 | 欧美xxxxx性| 把美女屁股眼扒开图片 | 美女黑人做受xxxxxⅹ | 精品无人乱码一区二区三区 | 亚洲国产黄色 |