MySQL计算空值

问题描述 投票:0回答:1

我正在尝试计算变量的特定结果。这是区域数据,我那里有缺失,我相信在尝试计算比率时会被漏掉。

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中指示缺失的方式是什么?

mysql count null missing-data
1个回答
0
投票

如果要包含空值,可以执行以下操作:

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;
© www.soinside.com 2019 - 2024. All rights reserved.