SQLServer 數(shù)據(jù)集合的交、并、差集運算
更新時間:2009年09月07日 17:52:58 作者:
SQLServer2005通過intersect,union,except和三個關鍵字對應交、并、差三種集合運算。
他們的對應關系可以參考下面圖示相關測試實例如下:
相關測試實例如下:
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*/
相關測試實例如下:
復制代碼 代碼如下:
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*/
您可能感興趣的文章:
相關文章
SQLServer2005與SQLServer2008數(shù)據(jù)庫同步圖文教程
要實現(xiàn)SQLServer2005與2005的數(shù)據(jù)庫同步的話,直接用鏡像就可以實現(xiàn)。但是如果同步 SQLServer2008的話,2005的實例是連接不上08的。低版本的無法連接高版本的。所以我們可以通過復制的方式,也就是所謂的訂閱發(fā)布的方法來實現(xiàn)兩個不同版本數(shù)據(jù)庫的數(shù)據(jù)同步。2011-09-09
sql server2005實現(xiàn)數(shù)據(jù)庫讀寫分離介紹
對于負載均衡,筆者經(jīng)常接觸的當屬Oracle的負載均衡機制。下面我們重點介紹Sql Server 2005是如何實現(xiàn)負載均衡的,感興趣的朋友可以參考下哈2013-06-06
Sql server 備份還原后出現(xiàn) 受限制用戶 問題
怎么解決Sql Server 2005數(shù)據(jù)庫備份還原后出現(xiàn)“受限制用戶”,這是大家在數(shù)據(jù)庫備份還原后經(jīng)常遇到的問題,我們今天就來探討下.2020-03-03
SQL Server 2005 數(shù)據(jù)庫復制詳細介紹
這篇文章主要介紹了SQL Server 2005 數(shù)據(jù)庫復制技術,有時候我們需要將數(shù)據(jù)庫備份一份到別的服務器上,防止突發(fā)情況2014-08-08
Win2008中安裝的MSSQL2005后無法訪問的解決方法
最近筆者一直在使用Win2008系統(tǒng),不過發(fā)現(xiàn)一個很奇怪的問題,那就是在該系統(tǒng)上安裝了SQL2005后,再在其他計算機訪問該主機顯示不能訪問2014-07-07
SQL Server 2005 Express 安裝失敗解決辦法
本人重裝vs2005后,sql sever 2005 express卻一直安裝不上,造成寫好的網(wǎng)頁無法運行。多次卸載重裝無果2009-03-03

