我正在尝试计算变量的特定结果。这是区域数据,我那里有缺失,我相信在尝试计算比率时会被漏掉。
select date
count( case when region in ('') and sale=1 then id end),
count( case when region in ('') and sale=1 then id end)/ count(id)
from region
group by 1;
缺少计数('')的计数为0(但我知道有缺失),mysql中指示缺失的方式是什么?
如果要包含空值,可以执行以下操作:
select date
count( case when (region in ('') or region is null) and sale=1 then id end),
count( case when (region in ('') or region is null) and sale=1 then id end)
/ count(id)
from region
group by 1;