select b ,(case when count(b)=sum(case when a=null then 0 else 1 end) then 0 else count(b) end) from 表名 group by b
(A B 两个字段, 在B相同的情况下, 要对A有条件的记数,即只要A有一个非空, 就全部记数; A都为空, 也全部记数; A都不为空, 则都不记数
举例:
1. A B
* V1
V1 (记数结果 V1: 2)
2. A B
V1
V1 (记数结果 V1: 2)
3. A B
* V1
* V1 (记数结果 V1: 0)
)
温馨提示:内容为网友见解,仅供参考