select * from A where x+y not in (select x+y from B)

解决方案 »

  1.   

    你既然是从b表里select,就应该是
    select * from b where x,y not in (select x,y from a)
    试试看吧!对了,请把错误提示一并帖出来
      

  2.   

    这个SQL应该有些问题,如果A表中X,Y分别是11,22,而B表X,Y分别是1,122,那么这个SQL就产生了歧义。
      

  3.   

    可以找一个A,B两表X,Y字段都没有的字符,假设是'@',那么这么写
    select * from B where X + '@' + Y not in (select X + '@' + Y from A)
      

  4.   

    呵呵~~完全同意~~chechy(chechy)~~
    没有SQL Server不能调试~~随手写的~~
      

  5.   

    To:chechy(chechy) ~~~这种方法不好的~~因为没有绝对一个A,B两表X,Y字段都没有的字符~~
    有更好的办法的~~不过网吧太吵了~~唉~~大脑迟钝了~~竟然想不起来了~~~
      

  6.   

    我刚才也在想这个问题,没办法,in操作符有些限制。必须让X,Y连接起来。
    呵呵,我在听电视新闻,脑子也不灵。
      

  7.   

    X, Y是什么类型啊,是什么数据库啊,如果允许数据类型转换,就好办了。以SQL Server和X, Y都是整型为例:select * from A where Convert(varchar(255), x)+':'+Convert(varchar(255), y) not in (select Convert(varchar(255), x)+':'+Convert(varchar(255), y) from B) 如果x, y的取值较小,比如说都小于65536,也可以用
    select * from A where y*65536+x not in (select y*65536+x from B) 正宗的写法:
    select * from A
    minus
    select A.* from A, B where join B on A.x=B.x and A.y=B.y不过集合算法据说是很费时间,只能测测看了
      

  8.   

    纠正一下(我原来是想用left join,后来觉得不妥):正宗的写法:
    select * from A
    minus
    select A.* from A, B where A.x=B.x and A.y=B.y