SQL中All, Any, Some的意思

来源:互联网 发布:swift 商城源码 编辑:程序博客网 时间:2024/04/27 22:42

create table #A(id int)
go
insert into #A values(1)
insert into #A values(2)
insert into #A values(3)
insert into #A values(4)
go

--All:对所有数据都满足条件,整个条件才成立,例如:5大于所有返回的id
select *
from #A
where 5>All(select id from #A)
go

--Any:只要有一条数据满足条件,整个条件成立,例如:3大于1,2
select *
from #A
where 3>any(select id from #A)
go
--Some和Any一样 

备注:Any的用法中,在作数字比对时,也可以改用先select subquery的min/max value的方法,某些情况下效率更高

 
原创粉丝点击