`

比较两个数据集是否相等minus,union all

 
阅读更多
--minus的作用简单来说是去同留异,例:
select * from table where rownum<10
minus select * from table where rownum<5;

 

(select * from table where rownum<10
minus select * from table where rownum<5)
union all 
(select * from table where rownum<10
minus select * from table where rownum<8)

 


若存在不同会列出数据

以下供参考:

*****************************

SQL> select * from test001; 

NAME 
---------- 
1 
2 
3 
4 
5 

SQL> select * from test002; 

NAME 
---------- 
4 
5 
6 
7 
8 

SQL> select * from test001 minus select * from test002; 

NAME 
---------- 
1 
2 
3 

SQL> select * from test001 union select * from test002; 

NAME 
---------- 
1 
2 
3 
4 
5 
6 
7 
8 

按照上面的结果,查询ab交集只需要 
select * from A minus (select * from A minus select * from B); 

SQL> select * from test001 minus (select * from test001 minus select * from test002); 

NAME 
---------- 
4 
5
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics