SELECT count(*)
FROM [SELECT 表1.A, sum(表1.B) AS BB
FROM 表1
GROUP BY 表1.A]. AS [last]
WHERE BB=-1;
'因为True+false=-1 ,以上语句在access2003中通过。结果为1
'只是不知道1个A 会不会有很多B状态
比如
1 true
1 true
1 false
1 false
这样的话就不行了。另外提问者没有交待清楚B字段是何类型,我理解应该是Boolean型的吧。可是那个Flase一会大写,一会小写,会不会是文本型呢?提问者要告诉我们是在哪个系统中用的。不同的系统略有差异啊。
应该很简单呀
select count(distinct(t1.A))
from table t1, table t2
where t1.A=t2.A and t1.B !=t2.B
SELECT COUNT1+COUNT2 FROM
(select A,count(*) COUNT1 from table_name where B='True' GROUP BY A) C,
(select A,count(*) COUNT2 from table_name where B='False' OR B='false' GROUP BY A) D
where C.A=D.A
1楼的回答跟我类似不过纠正下:
select distinct A from mytable where A in
(
select A from mytable where B='true '
) and A in
(
select A from mytable where B='false '
)
select a, sum(T) as T, sum(F) as F
(select a, case b = 'True' then 1 else 0 end as T,
case b <> 'True' then 1 else 0 end as F
from 表)
group by a
having sum(T) > 0 and sum(F) > 0