日期:2014-05-18  浏览次数:20550 次

求一条检索SQL语句..
有表A:
a b c
1 33 kk
2 33 kk
3 33 mm
4 55 mm
5 66 kk
6 66 ff

要得到以下结果:
a b c
3 33 mm
5 66 kk
6 66 ff

即查出b列相同而c列不同的记录 


------解决方案--------------------
select m.*
from A m,A n
where m.b = n.b and m.c <> n.c
order by m.a
------解决方案--------------------
select distinct m.*
from A m,A n
where m.b = n.b and m.c <> n.c
and not exists 
(
select b,c
from A
where b = m.b and c = m.c
group by b,c
having COUNT(*) > 1
)
order by m.a