c1     c2     c3     c4     c5     
     ---------------------- 
    c         e       c       e       f 
    2         e       c       e       b 
    a         b       c       e       d 
    4         w       q       f       y 
    5         g       a       f       t 
    6         v       e       w       r 

解决方案 »

  1.   

    我想查找出除第一行以外的数据,即c1=c3且c2=c4的不要。
    select * from tabletst where c1!=c3 and c2!=c4,这个语句查不到第二条,但我要第二条,怎么整。
      

  2.   

    我想查找出除第一行以外的数据,即c1=c3且c2=c4的不要。
    select * from tabletst where c1!=c3 and c2!=c4,这个语句查不到第二条,但我要第二条,怎么整。
      

  3.   

    ----------------------------------------------------------------
    -- Author  :fredrickhu(小F,向高手学习)
    -- Date    :2011-09-05 10:18:52
    -- Verstion:
    --      Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (Intel X86) 
    -- Apr  2 2010 15:53:02 
    -- Copyright (c) Microsoft Corporation
    -- Enterprise Evaluation Edition on Windows NT 6.1 <X64> (Build 7600: ) (WOW64)
    --
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    go 
    create table [tb]([c1] varchar(1),[c2] varchar(1),[c3] varchar(1),[c4] varchar(1),[c5] varchar(1))
    insert [tb]
    select 'c','e','c','e','f' union all
    select '2','e','c','e','b' union all
    select 'a','b','c','e','d' union all
    select '4','w','q','f','y' union all
    select '5','g','a','f','t' union all
    select '6','v','e','w','r'
    --------------开始查询--------------------------
    select * from tb t where exists(select 1 from tb where c3=t.c3 and c4=t.c4 and c1<>t.c1)
    ----------------结果----------------------------
    /* c1   c2   c3   c4   c5
    ---- ---- ---- ---- ----
    c    e    c    e    f
    2    e    c    e    b
    a    b    c    e    d(3 行受影响)*/
      

  4.   

    select * from tabletst where c1!=c3 or c2!=c4
      

  5.   

    我想查找出除第一行以外的数据,即c1=c3且c2=c4的不要。
    select * from tabletst where c1!=c3 and c2!=c4,这个语句查不到第二条,但我要第二条,怎么整。
      

  6.   

    呵呵,是我还没说完,结果点发表帖子了,后来想改也改不了。现在解决了,谢谢大家。
    不过我还是感觉奇怪啊,为什么select * from tabletst where c1!=c3 and c2!=c4 会选不出第二条记录
      

  7.   

    and是交集
    你第二条的记录c1和c3不相等
    但是c2和c4相等啊
    我勒个去
      

  8.   

    但是又可以这样理解,只有c1!=c3并且c2!=c4时才为真, 第二条记录,不满足这个为真的条件啊。
      

  9.   

    本帖最后由 roy_88 于 2011-09-05 11:01:02 编辑