程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> 其他數據庫知識 >> 更多數據庫知識 >> SQLServer 數據集合的交、並、差集運算

SQLServer 數據集合的交、並、差集運算

編輯:更多數據庫知識

他們的對應關系可以參考下面圖示相關測試實例如下:
 
相關測試實例如下:
復制代碼 代碼如下:
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*/

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved