如果onefield 只有0或1两个值,可以使用分组计算:
select onefield , count(1) cot from table group by onefield;
结果中会如下显示:
onefield cot
0 数量
1 数量
另一种方案:
select sum(case when onefield = 0 then 1 else 0 end) zero_count,
sum(case when onefield = 1 then 1 else 0 end) one_count from table;
select cout(*) from onefield=0 or onefield=1
my sql 不会