我想实现如下效果:Select top 10 *
 from A
 where (a,b) not in(select top 10 a,b from A)是对一个表的2个条件的not in 操作,如何实现?

解决方案 »

  1.   

    select top 10 * from A as A1
    where not exists(select top 10 a,b from A as A2 where A1.a=A2.a and A1.b=A2.b)试试。手写的,没开SQL试过,不对请见谅
      

  2.   

    Select top 10 *
    from A
    where a not in(select top 10 a from A) and b not in(select top 10 b from A)
      

  3.   

    把表重命下名,(select……) a
      

  4.   

    上边已经有答案了.我就不写了.另外对于两个字段not in效率非常低.
    可以改成用left join
      

  5.   

    select id from users as e
      

  6.   

    如果我的条件改成left join,如何写,请指教?
      

  7.   

    可能,我被你写的sql误导了。你还是直接把你想要的效果,用文字说出来,我试试帮你写写。
      

  8.   

    a   b    c
    1   1    2
    1   2    3
    2   1     3
    2    2    4
    3    1    2
    3    4    2
    4    5    2
    4    6    3
    5    1    3
    5     4   3
    5    5    2这样的表,我想通过2个变量,来取从第x条开始,取y条记录
    如果有一列是唯一的,就好办了,直接如下实现:
    select top y * from A where id not in (select top x id from A)
    但现在是两列联合起来做唯一键,
    select top y * from A where (a,b) not in (select top x a,b from A)
    这样的条件如何实现呢?
      

  9.   


    Select top 10 * from A x
    left join (select top 10 a from A) y on x.a = y.a
    left join (select top 10 b from A) z on x.b = z.b
    where y.a is null and z.b is null
    写sql的时候可以不用到not in尽量不要用,not in效率太不好了
      

  10.   

    Select top 10 *
    from A
    where a not in(select top 10 a from A) and b left join (select top 10 b from A)
      

  11.   

    where '@#$@'+a+b+'@#$@' not in(select top 10 '@#$@'+a+b+'@#$@' from A) 
      

  12.   

    Select top 10 * 
    from A  left join (select top 10 a,b from A) b on a.a=b.a and a.b=b.b where b.a is null  and b.b is null