
怎么在SQL中查询某列的数据全部相同?
例如有下表idnamesexage1abc0202abc0213abd1204abe2245abc0246abe3217abd022要求查询结果是:表中相同name字段并...
例如有下表
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的记录 展开
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的记录 展开
展开全部
你这个需求是最简单的
select * from table where name = 'abc' and sex = '0'
就能满足你的要求
select * from table where name = 'abc' and sex = '0'
就能满足你的要求
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select *
from tab t1
where exists(Select 1 from tab where name = t1.name and sex = t1.sex and id <> t1.id)
from tab t1
where exists(Select 1 from tab where name = t1.name and sex = t1.sex and id <> t1.id)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select count(*)-count(distinct 某列) rom tables;
为零则相同
为零则相同
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select * from 表名 where name='abc' and sex='0'
就这样就可以实现了
就这样就可以实现了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
同一楼
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询