一张表中,一个字段的值有另一个字段多个值,怎么查询

一张表Table里面,一个字段A对应另一个字段B多个数据,怎么查符合这一要求的数据?

A B
1 a
1 a
2 a
2 b

要查出
A B
2 a
2 b

可以向用group by 加 去从 distinct 来处理,以下是oracle实例

select * from 表
where A IN(SELECT A FROM 表 group by A having count(distinct B)>1)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-07-13
select DISTINCT A,B from Table
相似回答