Reputation: 701
I want to count how many rows has given value (1) and count how many row has value(0)
id XXX 1 <== value 0 or 1
id YYY 1
id ZZZ 0
so the result would be
ones | zeros
2 | 0
thx in advance
Upvotes: 0
Views: 49
Reputation: 20804
Something like this should work:
select sum(case when value = 1 then 1 else 0 end) ones
, sum(case when value = 0 then 1 else 0 end) zeros
Upvotes: 2
Reputation: 17481
Try this
select sum(if(value=0,1,0)) as zeros,
sum(if(value=1,1,0)) as ones
from mytable
Upvotes: 1