加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 15:02:31 所属栏目:MsSql教程 来源:网络整理
导读:SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算。 ? 他们的对应关系可以参考下面图示 ? ?????? 相关测试实例如下: ?usetempdb go if (object_id ('t1' ) isnotnull ) droptablet1 if (object_id ('t2' ) isnotnull ) drop

SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算。
?
他们的对应关系可以参考下面图示
?


?????? 相关测试实例如下:

?usetempdb
go
if (object_id ('t1' ) isnotnull ) droptablet1
if (object_id ('t2' ) isnotnull ) droptablet2
go
createtablet1 (aint )
insertintot1select1unionselect2unionselect3
createtablet2 (aint )
insertintot2select3unionselect4unionselect5
go
select*fromt1unionselect*fromt2
go
/* 求表并集
1
2
3
4
5*/
select*fromt1unionall?? select*fromt2
go
/*求表并集不过滤重复
1
2
3
3
4
5*/
select*fromt1exceptselect*fromt2
go
/*求t1对t2的差集
1
2*/
select*fromt1intersectselect*fromt2
go
/*求t1对t2的交集
3*/


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/jinjazz/archive/2009/09/07/4527863.aspx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读