select * from tab where 状态=1 and 品种 not in (select 品种 from tab where 状态=0 )group by 品种 状态
select count(*)-sum(if(状态=1,1,0)) as 结果 from 表 group by 品种 HAVING 结果=0
select * from tb where 状态=0 and 品种 not in (select 品种 from tb where 状态=1) group by 品种 或 select 品种,count(distinct 品种) as aa from tb group by 品种 having count(distinct 品种)>=2
特别是上面一种 select * from tb where 状态=0 and 品种 not in (select 品种 from tb where 状态=1) group by 品种感觉确实没什么错误,而且select 品种 from tb where 状态=1单独查询也可以,把“select 品种 from tb where 状态=1”换成一组数组后也可以,但是放在一起就不行了,不知道为什么?
品种 状态 A 0 A 1 B 0 B 0 B 0 B 1 C 1 查询出来是 品种 状态 C 1 只有1的状态就查出来 你不是要这样的结果吗?
那你不妨分两步做, select 品种 into tb1 from tb where 状态=1 group by 品种select * from tb where 品种 not in (select 品种 from tb1) group by 品种
from tb
where 状态=0
and 品种 not in (select 品种 from tb where 状态=1)
group by 品种
或
select 品种,count(distinct 品种) as aa
from tb
group by 品种
having count(distinct 品种)>=2
select *
from tb
where 状态=0
and 品种 not in (select 品种 from tb where 状态=1)
group by 品种感觉确实没什么错误,而且select 品种 from tb where 状态=1单独查询也可以,把“select 品种 from tb where 状态=1”换成一组数组后也可以,但是放在一起就不行了,不知道为什么?
A 0
A 1
B 0
B 0
B 0
B 1
C 1
查询出来是
品种 状态
C 1
只有1的状态就查出来
你不是要这样的结果吗?
select 品种
into tb1
from tb
where 状态=1
group by 品种select * from tb
where 品种 not in (select 品种 from tb1)
group by 品种
的语句没有问题啊,你用的什么数据库??