Hive count(*) 会统计NULL,count(字段名)不统计NULL
Posted 二十六画生的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hive count(*) 会统计NULL,count(字段名)不统计NULL相关的知识,希望对你有一定的参考价值。
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
以上是关于Hive count(*) 会统计NULL,count(字段名)不统计NULL的主要内容,如果未能解决你的问题,请参考以下文章