insert into a (客户,货号,色,尺,数量)
SELECt 客户,货号,色,尺,数量 from b where (客户+货号+色+尺) not in (SELECt 客户+货号+色+尺 as id from a)
SELECt 客户,货号,色,尺,数量 from b where (客户+货号+色+尺) not in (SELECt 客户+货号+色+尺 as id from a)
解决方案 »
- SQL语句如何判断某字段值
- 一个简单的问题
- SQL服务器的登陆密码可否设置有效期?
- 救救我吧…我要抓狂了…关于SQL2005不能远程连接的问题
- 动态sql 如何写啊
- 初学SQL SERVER,请教一个问题·立马结分!
- 这样设计是否合理?
- 非常棘手之问题,求解50
- sql 循环问题,大侠们 帮帮忙!
- select ledid, (case when lendsplitid is null then ledid when '' then ledid else ledid + '-' + lendsplitid end) as lendida from t
- 怎样将在SQL Server7.0建的数据库转到SQL Server2000中????
- 我建了个ID为int型的为递增的字段,但当我insert 一条记录之后,怎样可取得刚刚insert的哪条记录的ID呢?
可能还是有点漏洞,写成这样应该就正确了:
where (客户 not in (SELECt 客户 from a)) and (货号 not in (SELECt 货号 from a)) and .....
SELECt 客户,货号,色,尺,数量
from b where (客户+货号+色+尺) not exists (
SELECt *
from a as tmp
where b.客户=tmp.客户 and
b.货号=tmp.货号 and
b.色=tmp.色 and
b.尺=tmp.尺)
你的好象有点问题。题目要求的是由“客户,货号,色,尺,数量”
共同决定记录的唯一性,你的意思成了“客户,货号,色,尺,数量”
每一个字段都必须不在第二个表中才加入到表一中。
WxmJun(FBI) 的最简洁!
如果你的是oracle,则select aa.* from a aa,b bb
where aa.a = bb.a(+) and aa.b= bb.b(+) and aa.c = bb.c(+) and aa.d = bb.d(+)
and bb.a is null and bb.b is null and bb.c is null and bb.d is null如果四个字段都不为空的话,只要一个 is null 的判断就可以了如果是mssql,类似的可以把写法翻译过去
这是效率最高的一种写法了