首页 > 数据库技术 > 详细

SQLServer数据集合的交、并、差三种集合运

时间:2014-01-14 21:22:29      阅读:619      评论:0      收藏:0      [点我收藏+]

SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算

他们的关系对应如下

bubuko.com,布布扣

createtablet1 (aint)
insertintot1select1unionselect2unionselect3
createtablet2 (aint)
insertintot2select3unionselect4unionselect5
go
select*fromt1unionselect*fromt2
go
/* 求表并集
1
2
3
4
5*/
select*fromt1unionallselect*fromt2
go
/*求表并集不过滤重复
1
2
3
3
4
5*/
select*fromt1exceptselect*fromt2
go
/*求t1对t2的差集
1
2*/
select*fromt1intersectselect*fromt2
go
/*求t1对t2的交集
3*/

本文转载http://www.cnblogs.com/AllUserBegin/p/3513082.html

SQLServer数据集合的交、并、差三种集合运

原文:http://www.cnblogs.com/Rikybk/p/3513108.html

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