求一SQL语句,急,在线等待,解决马上结贴!

foilsman 2006-03-12 05:39:29
表1:
字段A, 字段B, 字段C

表2:
字段A, 字段B, 字段C, 其它

怎样获得表2中:字段A, 字段B, 字段C三个字段与表1中的三个字段不能同时相等的记录
如:
(表1)
字段A 字段B 字段C
1 2 3

(表2)
字段A 字段B 字段C 其它
1 5 3 kk
2 2 7 ll
1 2 3 hh
1 3 3 yy

要求结果:

(表2)
字段A 字段B 字段C 其它
1 5 3 kk
2 2 7 ll
1 3 3 yy
...全文
71 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
foilsman 2006-03-12
  • 打赏
  • 举报
回复
谢谢!!
aniude 2006-03-12
  • 打赏
  • 举报
回复
create table biao1
(
字段a char(1),
字段b char(1),
字段c char(1)
)
insert into biao1 select '1','2','3'
create table biao2
(
字段a char(1),
字段b char(1),
字段c char(1),
其他 char(2)
)
insert into biao2 select '1','5','3','kk'
union all select '2','2','7','ll'
union all select '1','2','3','hh'
union all select '1','3','3','yy'
select * from biao2 where not exists(select * from biao1 where biao1.字段a=biao2.字段a and biao1.字段b=biao2.字段b and biao1.字段c=biao2.字段c)
drop table biao1,biao2
huailairen 2006-03-12
  • 打赏
  • 举报
回复

create table 表1(字段A int, 字段B int , 字段C int)

create table 表2(字段A int , 字段B int , 字段C int , 其它 varchar(20))

insert into 表1
select 1,2,3

select * from 表2
insert into 表2
select 1 ,5 ,3 ,'kk'
union select
2 ,2 ,7 ,'ll '
insert into 表2 select
1 ,2 ,3 ,'hh '
union select
1 ,3 ,3 ,'yy'

select *
from 表2 a
where not exists ( select * from 表1 b where a.字段A=b.字段A and a.字段B=b.字段B and a.字段C=b.字段C)

34,576

社区成员

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

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