insert into a (客户,货号,色,尺,数量) 
  SELECt 客户,货号,色,尺,数量 from b where (客户+货号+色+尺) not in (SELECt 客户+货号+色+尺 as id from a)

解决方案 »

  1.   

    没错,照wxmjun(FBI) 的做基本没有问题,使用in语句非常爽的。
     可能还是有点漏洞,写成这样应该就正确了:
    where (客户 not in (SELECt 客户  from a)) and (货号 not in (SELECt 货号  from a)) and .....
      

  2.   

    insert into a (客户,货号,色,尺,数量) 
      SELECt 客户,货号,色,尺,数量 
        from b where (客户+货号+色+尺) not exists (
            SELECt *
                 from a as tmp
                 where b.客户=tmp.客户 and 
                       b.货号=tmp.货号 and
                       b.色=tmp.色 and
                       b.尺=tmp.尺)
      

  3.   

    TO:  mornwoo(疾风之虫) 
        你的好象有点问题。题目要求的是由“客户,货号,色,尺,数量”
        共同决定记录的唯一性,你的意思成了“客户,货号,色,尺,数量”
        每一个字段都必须不在第二个表中才加入到表一中。
        WxmJun(FBI) 的最简洁!
      

  4.   

    只是,你们的效率都是特别的低  :)使用not in 效率尤其低
    如果你的是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,类似的可以把写法翻译过去
    这是效率最高的一种写法了