当两个字段都为null时,计数为null

  • 本文关键字:null 字段 两个 sql hiveql
  • 更新时间 :
  • 英文 :


如何计算每个日期的null(当注释和卖家为null时(?

order_time不是日期/时间字段

所附图片上的数据示例解释了我试图在这里实现的

在此处输入图像描述

如何计算每个日期的null(当注释和卖家为null时(?

大概你想要这样的东西:

select date, sum(case when comment is null and seller is null then 1 else 0 end) as both_null
from t
group by date;

在where子句的帮助下,选择注释和卖方列中只有null的行。然后它只是简单地用groupby计数。我也将order_time列转换为date。

select cast(order_time as date) order_date, count(*) null_count
from yourtable
where comment is null and seller is null
group by  cast(order_time as date);

最新更新