首页 > 数据库技术 > 详细

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

时间:2016-02-09 06:40:07      阅读:205      评论:0      收藏:0      [点我收藏+]
他们的对应关系可以参考下面图示相关测试实例如下:
技术分享 
相关测试实例如下:
复制代码 代码如下:

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*/

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

原文:http://www.jb51.net/article/19914.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!