hiveql聚合:两个值之间的差异

qjp7pelc  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(369)

我使用的是hive和hadoop。我在寻找一个函数(hiveql),它允许在一天的最后一个值和第一个值之间存在差异。每个资源名每5分钟记录一次数据(计量器或计数器,其增量),并且我希望有一个聚合,每个资源名(mac)每天有一个值。插图

c0vxltue

c0vxltue1#

使用分析函数 first_value 以及 last_value :

select colldate, 
           max(last_success - first_success) as success,
           max(last_conmiss - first_conmiss) as conmiss,
           resourcename
    from
    (
    select 
         first_value(success) over(partition by resourcename, colldate order by colltime) first_success,
         last_value(success) over(partition by resourcename, colldate order by colltime) last_success,
         first_value(conmiss) over(partition by resourcename, colldate order by colltime) first_conmiss,
         last_value(conmiss) over(partition by resourcename, colldate order by colltime) last_conmiss,
    colldate, resourcename
    from (select s.*, to_date(s.colltime) colldate from table s) s
    )s
group by colldate, resourcename;

请参阅以下文档:https://cwiki.apache.org/confluence/display/hive/languagemanual+windowingandanalytics

相关问题