select Axx
  from
(
   select Axx
     from table
      where Bxx=10 
   group by Axx
   union all
   select Axx
     from table
      where Bxx=11 
   group by Axx
)
group by Axx
having count(*)>1;

解决方案 »

  1.   

    select a.axx from table a,table b where a.axx=b.axx and a.bxx in (10,11)
      

  2.   

    如果你的要求是返回同时具有bxx=10和bxx=11的记录,那clwyf(糕手)的写法是对的。
    TonyJoule(寒星)的写法等同于select axx from tablename where bxx in (10,11),返回的结果肯定不对。
    下面是另一种写法,可能效率更高些。
    select distinct axx
    from tablename x
    where exists (select 'x' from tablename
                   where bxx = 10
                     and axx = x.axx)
      and exists (select 'x' from tablename
                   where bxx = 11
                     and axx = x.axx)如果你要求是返回bxx=10或者bxx=11,TonyJoule(寒星)的写法返回结果是对得,但是应该简化成上述select distinct axx from tablename where bxx in (10,11),
      

  3.   

    呵呵,我觉得上面的讨论很好,我也提一种方法,使用导出表实现。SELECT tb1.AXX FROM
    (SELECT AXX FROM TB_AXX_BXX WHERE BXX=10)tb1 
    JOIN
    (SELECT AXX FROM TB_AXX_BXX WHERE BXX=11)tb2
    ON tb1.AXX = tb2.AXX
      

  4.   

    多谢各位!
    我想再问一下union all语句和join语句的作用是什么,谢谢!
      

  5.   

    Join就是连接了,你看看sql Server的Books Online好了
      

  6.   

    好像跟我以前问的一个问题是一样的……http://www.csdn.net/expert/Topic/270/270950.shtm