例表:
A列   B列
100   -1
100   21
200   -1当B列里有21时,不取A列的100结果:
A列   B列
200   -1

解决方案 »

  1.   

    select * from tb where b <> 21
      

  2.   

    select (case when b=21 then 默认值 else a end) a,b from tb
      

  3.   

    这问题表达的太不清楚了。难道是这意思?
    select * from tb where a not in(select distinct a from tb where b=21)
      

  4.   

    --例表:
    --A列 B列
    --100 -1
    --100 21
    --200 -1--当B列里有21时,不取A列的100--结果:
    --A列 B列
    --200 -1
    declare @t table(A列 int ,B列 int )
    insert into @t values( 100,-1)
    insert into @t values( 100,21)
    insert into @t values( 200,-1)
     
      select A列,B列 from @t where A列<>100 AND (select  COUNT( A列 )from @t where B列=21)>0A列          B列
    ----------- -----------
    200         -1(1 行受影响)
      

  5.   

    A列没有要求等于或不等于某值这样说吧,我是要查找 当A列相同的情况下,B列里不包含21的结果,只要B列里有21了,A列有相同值了也不显示
      

  6.   

    select * from table1 where b<>21
      

  7.   

    那就是这个啊!select * from tb where a not in(select distinct a from tb where b=21)
    还不是的话。你多给几行测试数据,和想要的结果。用文字表达,不如用数据表达。