SQL Server 中的 ALL、SOME 和ANY

 ALL、SOME 和 ANY是SQL Server 三个比较运算符,其中 SOME 和 ANY 是等效的

SOME 或 ANY:当表达式与子查询返回的至少一个值比较时满足比较条件,高防服务器 SOME 或 ANY 就返回 TRUE。否则返回 FALSE

ALL :当表达式与子查询返回的所有值比较时满足比较条件, ALL 就返回 TRUE。否则返回 FALSE

create table test01 ( num int) insert into test01 select 5 union select 6 create table test02 (num int) insert into test02 select 2 union select 3 union select 6 union select 7 select * from test01

select * from test02 

 

至此 test01 表中有数据: 5和 6 , test02表中有数据 :2,3,6,7

select num as num1 from test02 where num > all(select num from test01 ) select num as num2 from test02 where num > any(select num from test01 ) select num as num3 from test02 where num > some(select num from test01)

 

select num as num4 from test02 where num = all (select num from test01 ) select num as num5 from test02 where num = any(select num from test01 ) select num as num6 from test02 where num = some(select num from test01) 

 

select num as num7 from test02 where num <> all (select num from test01 ) select num as num8 from test02 where num <> any (select num from test01 ) select num as num9 from test02 where num <>some(select num from test01)

 

从上面的服务器租用测试结果看,= any 或 = some 与平时使用的 in 是等效的。

云服务器提供商
IT科技
上一篇:尽量不要在域名中出现特殊字符,这样的域名很容易导致访问者输入错误,同时给人留下不专业的印象,降低网站的可信度,并流失大量潜在客户。
下一篇:众所周知,com域名拥有最大的流通市场和流通历史。最好选择com域名,特别是在购买域名时处理域名。其次可以是cn域名、net域名、org域名等主流域名,现在比较流行的王域名和顶级域名,都是值得注册和投资的。