【问题标题】:MySQL counting null valuesMySQL计算空值
【发布时间】:2020-04-16 16:24:50
【问题描述】:

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

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;

missings('')的计数为0(但我知道有missings),mysql中有什么方法来表示missings?

【问题讨论】:

  • 样本数据和预期输出示例将大大有助于阐明规范。目前尚不清楚缺少什么。听起来我们可能想要返回 date 值在 region 中不存在的行...但这只是猜测。

标签: mysql count null missing-data


【解决方案1】:

如果你想包含空值,你可以这样做:

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;

【讨论】:

    猜你喜欢
    • 2012-03-03
    • 2018-11-15
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 2012-07-09
    • 2011-05-07
    • 1970-01-01
    • 2018-08-08
    相关资源
    最近更新 更多