【开窗】取最近直播标题和直播时长

问题描述:

一张表:test_over(uid, title, stime, etime, date)

字段comment:主播ID,直播间标题,开始直播时间戳,结束直播时间戳,日期分区

问题:求每个主播当天最近一次直播记录和全天总的直播时长

要求: shuffle次数最少


思路:

粒度是主播;时间周期是每天;需求是两个,第一,当天最近一次直播记录,第二全天总的直播时长;要求shuffle次数最低;


数据准备:

数据准备

create table test_over(

uid int comment '主播ID'

,title varchar(50) comment '直播间标题'

,stime int comment'开始直播时间戳'

,etime int comment'结束直播时间戳'

,mdate date comment'日期分区'

);

 

insert overwrite table test_over

select 1,'直播1',1591607704,1591609704,'2020-06-08'

union all

select 1,'直播2',1591617204,1591621204,'2020-06-08'

union all

select 1,'直播3',159

你可能感兴趣的:(Hive,笔试题)