左搜右搜[求助]

mzcih 2003-12-08 04:33:15
A、B两个表,格式一样,将两个表中(A有B没或B有A没)的数据筛选出来。

例子:

A表              B表
A列 B列 C列       A列 B列 C列
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3

3的记录因为B表没有就筛选出来。
...全文
46 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzcih 2003-12-09
  • 打赏
  • 举报
回复
即然没有,结帐算了。
mzcih 2003-12-08
  • 打赏
  • 举报
回复
大家还有更好的办法吗?
mzcih 2003-12-08
  • 打赏
  • 举报
回复
谢谢大家!但我想到更好的办法了。

SQL:Select * from A where A.A not in(select B.A from B)
erigido 2003-12-08
  • 打赏
  • 举报
回复
呵呵~~~
erigido 2003-12-08
  • 打赏
  • 举报
回复
只有up了,都让高手们说完了,我只有学习了~~~555
shuiniu 2003-12-08
  • 打赏
  • 举报
回复
理解成两个数据集合的差!

declare @A表 table(A列 int,B列 int ,C列 int)
declare @B表 table(A列 int,B列 int ,C列 int)


insert @A表 values(1,1,1)
insert @A表 values(2,2,2)
insert @A表 values(3,3,3)

insert @B表 values(1,1,1)
insert @B表 values(2,2,2)

select * from @A表 A
where not exists(select * from @B表 B where A.A列 = B.A列 and A.B列 = B.B列 and A.C列 = B.C列)

A列 B列 C列
----------- ----------- -----------
3 3 3

(所影响的行数为 1 行)
zjcxc 元老 2003-12-08
  • 打赏
  • 举报
回复
--下面是数据测试

--测试数据
declare @A表 table(A列 int,B列 int,C列 int)
insert into @a表
select 1,1,1
union all select 2,2,2
union all select 3,3,3

declare @B表 table(A列 int,B列 int,C列 int)
insert into @b表
select 1,1,1
union all select 2,2,2
union all select 4,4,4

--查询
select 表=case when a.a列 is null then 'B表' else 'A表' end
,A列=isnull(a.a列,b.a列)
,B列=isnull(a.b列,b.b列)
,C列=isnull(a.c列,b.c列)
from @A表 a full join @B表 b on a.a列=b.a列 and a.b列=b.b列 and a.c列=b.c列
where (a.a列 is null and a.b列 is null and a.c列 is null)
or (b.a列 is null and b.b列 is null and b.c列 is null)
order by 表

/*--测试结果
表 A列 B列 C列
---- ----------- ----------- -----------
A表 3 3 3
B表 4 4 4

(所影响的行数为 2 行)
--*/
zjcxc 元老 2003-12-08
  • 打赏
  • 举报
回复
select A列=isnull(a.a列,b.a列)
,B列=isnull(a.b列,b.b列)
,C列=isnull(a.c列,b.c列)
from A表 a full join B表 b on a.a列=b.a列 and a.b列=b.b列 and a.c列=b.c列
where (a.a列 is null and a.b列 is null and a.c列 is null)
or (b.a列 is null and b.b列 is null and b.c列 is null)

mzcih 2003-12-08
  • 打赏
  • 举报
回复
谢谢!但不行!
txlicenhe 2003-12-08
  • 打赏
  • 举报
回复
select * from A表 a
full join B表 b on a.A列 = b.A列 and a.B列 = b.B列 and a.C列 = b.C列
where a.A列 is null or b.A列 is null

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧