Hive count(*) 会统计NULL,count(字段名)不统计NULL

Hive 专栏收录该内容
121 篇文章 2 订阅
select count(*) 
from 
(
select 1  as c1
union all
select null as c1
) -- 2  , count(*) 包含null值


select count(c1) 
from 
(
select 1  as c1
union all
select null as c1
) -- 1  , count(c1) 不包含null值


select count(case when 1=1 then 1 else 0 end) ; -- 1

select count(case when 1<>1 then 1 else null end) -- 0 

select count(0)  -- 1

select count(null)  -- 0
select
type,
count(case when status = 3 then id else null end) as cnt
from (
select 
1 as id ,
2 as status,
1 as type
union ALL
select 
3 as id ,
4 as status,
1 as type
union ALL
select 
2 as id ,
3 as status,
2 as type
union ALL
select 
4 as id ,
3 as status,
2 as type
) t1
group by type
order by type ;

---------- 

select
type,
count(case when status = 3 then id else 0 end) as cnt
from (
select 
1 as id ,
2 as status,
1 as type
union ALL
select 
3 as id ,
4 as status,
1 as type
union ALL
select 
2 as id ,
3 as status,
2 as type
union ALL
select 
4 as id ,
3 as status,
2 as type
) t1
group by type
order by type ;

 end

  • 0
    点赞
  • 1
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值