
select from table a
where acol1 > all(select col1 from b )
意思 是 a表的 col1列,大于括号里面的 所有值
where acol1>any (select col1 from b)
意思 是 a表的 col1列,只要大于 括号里面的 一个值
where exists (select col1 from b)
意思 是 只要存在 值 就成立。
some 就不懂了
Any
说明:用于判断集合中是否有元素满足某一条件;不延迟。(若条件为空,则集合只要不为空就返回True,否则为False)。
1简单形式:
仅返回没有订单的客户:
var q =
from c in dbCustomers
where !cOrdersAny()
select c;
生成SQL语句为:
SELECT [t0][CustomerID], [t0][CompanyName], [t0][ContactName],
[t0][ContactTitle], [t0][Address], [t0][City], [t0][Region],
[t0][PostalCode], [t0][Country], [t0][Phone], [t0][Fax]
FROM [dbo][Customers] AS [t0]
WHERE NOT (EXISTS(
SELECT NULL AS [EMPTY] FROM [dbo][Orders] AS [t1]
WHERE [t1][CustomerID] = [t0][CustomerID]
))
All
说明:用于判断集合中所有元素是否都满足某一条件;不延迟
var q =
from c in dbCustomers
where cOrdersAll(o => oShipCity == cCity)
select c;
语句描述:这个例子返回所有订单都运往其所在城市的客户或未下订单的客户。
create table #test(code varchar(36),num int)
--all用法
insert into #test
select newid(),1
union all
select newid(),20
union all
select newid(),28
union all
select newid(),15
select from #test
--alter add用法
alter table #test
add name varchar(30)
----any用法,类似 in关键字
select from #test
where num > any(select num from #test)
--as asc用法
select code,num,name as colname
from #test
order by num asc
drop table #test
以上就是关于请问大家在sql中all,any ,exists ,some四个关键字怎么用全部的内容,包括:请问大家在sql中all,any ,exists ,some四个关键字怎么用、linq to sql any和all的区别、在sql serve中下面关键字怎么用,请举个小例子'add','alter','all','any','as' ,'asc'等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)