SQLServer 數(shù)據(jù)集合的交、并、差集運算
更新時間:2009年09月07日 17:52:58 作者:
SQLServer2005通過intersect,union,except和三個關(guān)鍵字對應(yīng)交、并、差三種集合運算。
他們的對應(yīng)關(guān)系可以參考下面圖示相關(guān)測試實例如下:
相關(guān)測試實例如下:
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
/*求表并集不過濾重復(fù)
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*/

相關(guān)測試實例如下:
復(fù)制代碼 代碼如下:
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
/*求表并集不過濾重復(fù)
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*/
您可能感興趣的文章:
相關(guān)文章
SQLServer2005與SQLServer2008數(shù)據(jù)庫同步圖文教程
要實現(xiàn)SQLServer2005與2005的數(shù)據(jù)庫同步的話,直接用鏡像就可以實現(xiàn)。但是如果同步 SQLServer2008的話,2005的實例是連接不上08的。低版本的無法連接高版本的。所以我們可以通過復(fù)制的方式,也就是所謂的訂閱發(fā)布的方法來實現(xiàn)兩個不同版本數(shù)據(jù)庫的數(shù)據(jù)同步。2011-09-09sql server2005實現(xiàn)數(shù)據(jù)庫讀寫分離介紹
對于負載均衡,筆者經(jīng)常接觸的當(dāng)屬Oracle的負載均衡機制。下面我們重點介紹Sql Server 2005是如何實現(xiàn)負載均衡的,感興趣的朋友可以參考下哈2013-06-06Sql server 備份還原后出現(xiàn) 受限制用戶 問題
怎么解決Sql Server 2005數(shù)據(jù)庫備份還原后出現(xiàn)“受限制用戶”,這是大家在數(shù)據(jù)庫備份還原后經(jīng)常遇到的問題,我們今天就來探討下.2020-03-03簡單有用的SQL腳本 (行列互轉(zhuǎn),查詢一個表內(nèi)相同紀(jì)錄等)
本文推薦的SQL腳本都是很實用的哦,學(xué)會了,對在工作中得心應(yīng)手,一起來學(xué)習(xí)學(xué)習(xí)吧。2010-04-04SQL Server 2005 數(shù)據(jù)庫復(fù)制詳細介紹
這篇文章主要介紹了SQL Server 2005 數(shù)據(jù)庫復(fù)制技術(shù),有時候我們需要將數(shù)據(jù)庫備份一份到別的服務(wù)器上,防止突發(fā)情況2014-08-08Win2008中安裝的MSSQL2005后無法訪問的解決方法
最近筆者一直在使用Win2008系統(tǒng),不過發(fā)現(xiàn)一個很奇怪的問題,那就是在該系統(tǒng)上安裝了SQL2005后,再在其他計算機訪問該主機顯示不能訪問2014-07-07SQL Server 2005 Express 安裝失敗解決辦法
本人重裝vs2005后,sql sever 2005 express卻一直安裝不上,造成寫好的網(wǎng)頁無法運行。多次卸載重裝無果2009-03-03