下面这种情况下,怎么写Where语句?
表中包含4对字段:
APart1 APart2  BPart1 BPart2 CPart1 CPart2 DPart1 DPart2
现在想找到4对字段完全不相同的记录,
每对字段相同与否的原则是,每对字段对应部分全不相同才认为不等。否则即相等。这样的Where语句怎么写啊?
我的写法是:有社么错误呢?Where
NOT
(
APart1  = BPart1   AND APart2   = BPart2 
OR
APart1  = CPart1   AND APart2  = CPart2 
OR
APart1  = DPart1   AND APart2  = DPart2
OR
BPart1 = CPart1     AND BPart2  = CPart2 
OR
BPart1 = DPart1   AND BPart2   = DPart2
OR
CPart1 = DPart1    AND CPart2  = DPart2
)

解决方案 »

  1.   

    --加括弧
    where 
    not (   (A1=B1 and A2=B2) 
         or (A1=C1 and A2=C2) 
         or (A1=D1 and A2=D2) 
         or (B1=C1 and B2=C2) 
         or (B1=D1 and B2=D2)
         or (C1=D1 and C2=D2)
        )
      

  2.   

    或者如下
    Where
    (APart1 <> BPart1 or APart2 <> BPart2 )
    and
    (APart1 = CPart1 or APart2 = CPart2 ) 
    and
    (APart1 = DPart1 or APart2 = DPart2)
    and
    (BPart1 = CPart1 or BPart2 = CPart2 )
    and
    (BPart1 = DPart1 or BPart2 = DPart2 )
    and
    (CPart1 = DPart1 or CPart2 = DPart2 )
      

  3.   

    晕,没改全,=全部改<>
    不过不改了,因为这么该也许还是不对,在这些字段可以null的时候不对null有点复杂,需要确定null是否等于null
      

  4.   

    --如下写法是正确的
    Where
    NOT
    (
      (APart1 = BPart1 AND APart2 = BPart2 ) 
    OR
      (APart1 = CPart1 AND APart2 = CPart2) 
    OR
      (APart1 = DPart1 AND APart2 = DPart2)
    OR
      (BPart1 = CPart1 AND BPart2 = CPart2) 
    OR
      (BPart1 = DPart1 AND BPart2 = DPart2) 
    OR
      (CPart1 = DPart1 AND CPart2 = DPart2)
    )