SQLServer 数据集合的交、并、差集运算

他们的对应关系可以参考下面图示相关测试实例如下:

相关测试实例如下:
<div class="codetitle"><a style="CURSOR: pointer" data="85618" class="copybut" id="copybut85618" onclick="doCopy('code85618')"> 代码如下:

<div class="codebody" id="code85618">
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
/

相关文章

本篇内容主要讲解“sqlalchemy的常用数据类型怎么使用”,感...
今天小编给大家分享一下sqlServer实现分页查询的方式有哪些的...
这篇文章主要介绍“sqlmap之osshell怎么使用”,在日常操作中...
本篇内容介绍了“SQL注入的知识点有哪些”的有关知识,在实际...
1. mssql权限sa权限:数据库操作,文件管理,命令执行,注册...
sql执行计划如何查看?在SPL庞大的数据中我们不知道如何查看...