【问题标题】:Hive query for selecting data points in between max date and previous 30 days for each unique id用于为每个唯一 ID 选择最大日期和前 30 天之间的数据点的 Hive 查询
【发布时间】:2020-08-23 04:25:12
【问题描述】:

数据包含多个时间戳上具有不同纬度和经度的唯一 ID。我想为每个唯一 ID 选择最近 30 天坐标的行。请帮助我了解如何运行查询。此日期在 Hive 表中。无法编写子查询

【问题讨论】:

    标签: sql hive hiveql ambari


    【解决方案1】:

    你可以使用窗口函数:

    select t.*
    from (select t.*,
                 max(date) over (partition by id) as max_date
          from t
         ) t
    where date > date_add(max_date, -30);
    

    【讨论】:

    • 谢谢@gordon linoff,我有一个简短的问题,hives 表是否通过 hive sql 查询接受 windows 功能
    • @akshaydirisala 。 . . Hive SQL 支持 windows 函数。
    • 运行以下配置单元查询以从配置单元表中提取最近日期和前 30 天的唯一 ID 之间的数据,但无法使用配置单元 sql 查询中的子查询提取数据,请告诉我我是什么做错了。 Select temp.x,temp.y,temp.z,temp.w from (select x,y,z,w, max(y) over (partition by x) as max_date from t1 as temp) temp where t1 .y>date_add(max_date,-30); 错误:编译语句时出错:FAILED:ParseException line 3:0 cannot identify input near 'select' 'column name' ',' in join source (state=42000 ,code=40000) @gordon
    • @akshaydirisala 。 . .您的查询有问题,但不应该是窗口函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多