我自己摸索出来两种,其他的统计都差不多
- dept=10 的加1 不能省去or null 不然会变成 总和
select count ( dept = '10' or null) from dept
- 如果满足dept=10 则加1 否则为null(切记不能不能为0,为0的话会统计总和)
select count(if (dept = '10', 1 ,null)) from dept
- 这是第三种 dept= 10 则加1
select sum(case when dept = '10' then 1 else 0 end ) from dept