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;
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;
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),
(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
我想再问一下union all语句和join语句的作用是什么,谢谢!