hive:函数:聚合函数:count() 及多用法之count中使用函数

业务情景一: 

select
	count(first_interview) first_interviews,
	count(submit_time) submit_time,
	count(length(concat(submit_time,bg_time))>26) submit_time,
	count(followupdate) followupdate,
	count(arrivaldate) arrivaldate,
	count(*) reports
	from dws.dws_awa_t_cal_recomperiods_result2
	group by business_line,region,office,team,fullname

结果:

1	0	0	1	1	3
39	0	0	0	0	119
46	0	0	5	5	215
35	1	1	5	4	61
55	0	0	1	0	156
1	0	0	0	0	8
12	0	0	0	0	35
3	0	0	0	0	5
29	0	0	0	0	89
0	0	0	0	0	1
47	0	0	1	1	181
29	0	0	1	1	72
58	0	0	3	3	156
4	0	0	0	0	24
4	0	0	0	0	16
42	1	1	2	2	154
2	0	0	0	0	18

分析:为什么count不同字段得出来的结果却不同?

原因是coun计数的是检索行中“非空”记录数。

业务情景二:

是否可以同时count两个字段,或者说我要同时判断两个字段是否有值,然后才count计数加上1,答案是可以的。

如上sql中有一句:

count(length(concat(submit_time,bg_time))>26) submit_time,

这句sql意思就是先连接两个字段,并通过连接后的字段长度,来判断是否两个字段都有值,符合我们条件的才会count计数加上1。

猜你喜欢

转载自blog.csdn.net/weixin_38750084/article/details/93492663
今日推荐