集合C=集合B-集合A 的查询怎样写?
集合B结构如下所示:
T1 T2 T3
集合A结构如下所示:
t1 t2 t3
集合A与B的结构完全相同.
求 集合B-集合A
条件:当 t1t2=T1T2时 认为两记录相同.\
请求各位帮助
问题点数:20、回复次数:3Top
1 楼churchatp1(别看资料,看聊效!)回复于 2005-09-23 15:08:31 得分 15
select * from b where not exists(select 1 from a where a.t1=b.t1 and a.t2=b.t2)Top
2 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-09-23 15:08:39 得分 5
--try
select * from B a where not exists (select 1 from 表B inner join 表B where T1=a.T1 and T2=a.T2)Top
3 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-09-23 15:13:42 得分 0
--我上面有点问题,
--测试环境
declare @t1 table (t1 int ,t2 int ,t3 int)
insert into @t1 select 1,2,3
union all select 1,2,4
union all select 1,3,4
union all select 2,3,4
union all select 3,3,4
union all select 5,3,4
declare @t2 table (t1 int ,t2 int ,t3 int)
insert into @t2 select 1,2,3
union all select 1,2,4
--查询
select * from @t1 a where not exists
(select 1 from @t2 where T1=a.T1 and T2=a.T2)
--结果
t1 t2 t3
----------- ----------- -----------
1 3 4
2 3 4
3 3 4
5 3 4
(所影响的行数为 4 行)
Top




