首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求A表和B表的差集,该怎么处理

2012-04-18 
求A表和B表的差集有A表和B表,表结构相同,如:A表ABC11河北12天津。。。。。B表ABC11河北12天津。。。。。想求出B表比A

求A表和B表的差集
有A表和B表,表结构相同,
如:A表
A B C
1 1 河北
1 2 天津
。。。。。


B表
A B C
1 1 河北
1 2 天津
。。。。。

想求出B表比A表多出来的记录

[解决办法]

SQL code
select * from B where not exists(select 1 from A where A.A=B.A and A.B=B.B and A.C=B.C)
[解决办法]
select b.* from b where not exists(select 1 from a where a.a = b.a and a.b = b.b and a.c = b.c)
[解决办法]
select b.* from b where not exists(select 1 from a where a.a = b.a and a.b = b.b and a.c = b.c)

热点排行