HiveSQL某天每个直播间最大在线人数

一张表dwd_user_log 有如下字段:
1)直播间: live_id
2)用户:userid
3)时间戳:date_stamp
4)登陆类型:entry_type (登入in和登出out)

求某天每个直播间最大在线人数?

select live_id,max(total_users) max_total_users
from ( select
live_id
,userid
,date_stamp
,sum(ind) over (partition by live_id order by date_stamp) total_users
from (select
live_id
,userid
,date_stamp
,case when entry_type = ‘in’ then 1
when entry_type = ‘out’ then -1
else 0 end ind
from dwd_user_log
where date_stamp > start_time and date_stamp < end_time
) t1
) t2
group by live_id
;

你可能感兴趣的:(数据仓库技术体系,hive)