怎么在SQL中查询某列的数据全部相同?

例如有下表

id name sex age
1 abc 0 20
2 abc 0 21
3 abd 1 20
4 abe 2 24
5 abc 0 24
6 abe 3 21
7 abd 0 22

要求查询结果是:表中相同name字段并且sex记录也全部相同
例:name记录为abc,abc的sex记录都为0的记录

第1个回答  2011-11-28
你这个需求是最简单的
select * from table where name = 'abc' and sex = '0'
就能满足你的要求
第2个回答  推荐于2016-04-16
select *
from tab t1
where exists(Select 1 from tab where name = t1.name and sex = t1.sex and id <> t1.id)本回答被提问者采纳
第3个回答  2015-10-23
select count(*)-count(distinct 某列) rom tables;
为零则相同
第4个回答  2011-11-28
select * from 表名 where name='abc' and sex='0'
就这样就可以实现了
第5个回答  2011-11-28
同一楼