SQL Server 中的 ALL、SOME 和ANY
2023-03-14 09:41:31 时间
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 是等效的。
相关文章
- 谷歌 Chrome OS 虚拟键盘将支持黑暗主题、Unicode 14 表情符号和 Linux 应用输入
- Linux 内核静态追踪技术的实现
- 苹果 Safari 浏览器 16.1 新增支持通行密钥、Web 通知、Apple Pencil 悬停体验等
- Linux 系统查看磁盘可用空间的五个命令
- 温故知新-EverDB容器化之旅
- WPS新增支持重磅功能!告诉你XLOOKUP有多强
- Windows 10系统怎么进行蓝牙连接?Windows 10系统蓝牙链接操作步骤
- 你知道吗?Windows 11的这11个功能最糟糕
- 微软Windows 11封杀第三方浏览器工具:默认打开就得使用Edge 别的不行
- 在苹果 M1 上运行 Linux 虚拟机变得容易了
- 微软 Windows 11 预览版已屏蔽 Edge Deflector,链接重定向修改软件失效
- 使用 Linux cowsay 命令制作丰富多彩的节日问候
- HarmonyOS集成HMS Core服务--小白入坑操作(2)
- 为什么动态链接库以"错误"的方式被卸载?
- 手把手教你打造你专属的 Kubectl,让输出变的更加绚丽多彩
- Linux驱动实践:带你一步一步编译内核驱动程序
- 新版DevEco不用USB线下载程序
- 一文看懂:网址,URL,域名,IP地址,DNS,域名解析
- Linux 是洗衣粉!关于Linux 的10个趣事
- PostgreSQL 的并行框架