如下:
a b
---------------------
苹果 0
苹果 美国
苹果 法国
梨 0
梨 英国
梨 德国
香蕉 德国
香蕉 瑞典
香蕉 意大利
想得到的结果:( SQL如何写,谢谢 )
a count
----------------
香蕉 3
a b
---------------------
苹果 0
苹果 美国
苹果 法国
梨 0
梨 英国
梨 德国
香蕉 德国
香蕉 瑞典
香蕉 意大利
想得到的结果:( SQL如何写,谢谢 )
a count
----------------
香蕉 3
from tb
where a= '香蕉'
group by a
where a not in
(
select a from tbl where b=0
)
group by a
from tb
where a= '香蕉'
group by a
t.a,
count(t.*) as [count]
from
表名 t
where
not exists(select 1 from 表名 where a=t.a and b=0)
group by t.a
where a not in
(
select a from tbl where b=0
)
group by a这个正解