SQL ANY&所有运算符 [英] SQL ANY & ALL Operators
问题描述
我已经开始使用sql,并且对ANY
和ALL
运算符了解很多.有人可以向我解释它们所使用的查询类型以及它们如何工作吗?
I have started using sql and have heard much about the ANY
and ALL
operators. Can somebody explain to me the kind of queries they are used in and how they work?
推荐答案
ANY
和ALL
运算符允许您在单个列值和一系列其他值之间进行比较.例如:
The ANY
and ALL
operators allow you to perform a comparison between a single column value and a range of other values. For instance:
select * from Table1 t1 where t1.Col1 < ANY(select value from Table2)
ANY
表示如果该范围内任何值的运算为true,则将满足条件. ALL
表示仅当该范围内的 all 值的运算为true时,条件才会得到满足.
ANY
means that the condition will be satisfied if the operation is true for any of the values in the range. ALL
means that the condition will be satisfied only if the operation is true for all values in the range.
要使用一个可能更接近家庭的示例,请执行以下操作:
To use an example that might hit closer to home, doing this:
select * from Table1 t1 where t1.Col1 = ANY(select value from Table2)
与执行此操作相同:
select * from Table1 t1 where t1.Col1 in (select value from Table2)
这篇关于SQL ANY&所有运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!