hive之对比count 和sum

    根据条件,分别累加,达到计数目的co


  sum(case when status=1  then 1 else 0 end) 推荐此语句cas

  sum(case when status=2 then 1 else 0 end)错误

  sum(case when status=3 then 1 else 0 end)

 

  

 下面语句是错误的:
  count(case when status=1  then 1 else 0 end) 

  count(case when status=2 then 1 else 0 end)

  count(case when status=3 then 1 else 0 end)

三条语句,结果相同,主要是由于count0 count1结果相同

   修改成 count(case when status=1  then orderid end) 

  不推荐此用法,理由以下:通常if-else 配对出现。

相关文章
相关标签/搜索