sql语句,同张表内,两个字段A,B,条件是查出b中多个数据符合a字段的值
问题描述:
库名
a b
a 0
a 1
b 0
c 1
d 0
d 1
需要查出同时有0和1 下a字段的值,我并不知道A表
结果是:
a 0
a 1
d 0
d 1
答
select *
from 表
where a in (select a
from 表
where b in (0, 1)
group by a
having count(distinct b) = 2)
答
where条件b=0 and b =1,group by 过滤有相同的值这样吗
答
select a from
(
select * from 表 a where b in (0,1)
)
having count(b)=2