SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算。
他们的对应关系可以参考下面图示
相关测试实例如下:
use
tempdb
go
if
(object_id
('t1'
) is
not
null
) drop
table
t1
if
(object_id
('t2'
) is
not
null
) drop
table
t2
go
create
table
t1
(a
int
)
insert
into
t1
select
1
union
select
2
union
select
3
create
table
t2
(a
int
)
insert
into
t2
select
3
union
select
4
union
select
5
go
select
*
from
t1
union
select
*
from
t2
go
/* 求表并集
1
2
3
4
5*/
select
*
from
t1
union
all
select
*
from
t2
go
/*求表并集不过滤重复
1
2
3
3
4
5*/
select
*
from
t1
except
select
*
from
t2
go
/*求t1对t2的差集
1
2*/
select
*
from
t1
intersect
select
*
from
t2
go
/*求t1对t2的交集
3*/
分享到:
相关推荐
SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算。
主要介绍了sql server 交集,差集的用法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
6.3 EXCEPT(差集)集合运算 6.4 集合运算的优先级 6.5 避开不支持的逻辑查询处理 6.6 总结 6.7 练习 6.8 解决方案 第7章 透视、逆透视及分组集 7.1 透视转换 7.2 逆透视转换 7.3 分组集 7.4 ...
6.3 EXCEPT(差集)集合运算 6.4 集合运算的优先级 6.5 避开不支持的逻辑查询处理 6.6 总结 6.7 练习 6.8 解决方案 第7章 透视、逆透视及分组集 7.1 透视转换 7.2 逆透视转换 7.3 分组...
6.3 EXCEPT(差集)集合运算 6.4 集合运算的优先级 6.5 避开不支持的逻辑查询处理 6.6 总结 6.7 练习 6.8 解决方案 第7章 透视、逆透视及分组集 7.1 透视转换 7.2 逆透视转换 7.3 分组集 7.4 总结 7.5 ...
SQL Server中的集合运算包括UNION(合并),EXCEPT(差集)和INTERSECT(相交)三种。 集合运算的基本使用 1.UNION(合并两个查询结果集,隐式DINSTINCT,删除重复行) --合并两个提取表/派生表(derived table), 返回结果为:...
实例005 下载并安装JRE执行环境 8 实例006 编程输出星号组成的等腰三角形 9 1.2 开发工具 11 实例007 下载最新的Eclipse 11 实例008 为最新的Eclipse安装中文语言包 12 实例009 活用Eclipse的工作空间 14 实例010 在...
如果我们想查询跟索引有关的数据字典时,可以用下面这条SQL语句: SQL>select * from dictionary where instr(comments,'index')>0; 如果我们想知道user_indexes表各字段名称的详细含义,可以用下面这条SQL语句:...