Select 来自 Hive Table,其中日期小于最大日期

Select from a Hive Table where date less than max date

我正在尝试 select * 从一个 Hive table 中,其中一个名为 TRANS_DATE 的日期列 >= 大于最大值 TRANS_DATE 之前的 365 天.

以下是我迄今为止尝试过的查询:

select * from TABLE
where (TRANS_DATE > DATE_SUB(max(TRANS_DATE), 365)) and 
        (TRANS_DATE < max(TRANS_DATE));

以下是我得到的错误: "Error while compiling statement: FAILED: SemanticException [Error 10128]: Line 2:28 Not yet supported place for UDAF 'max'"

日期格式的示例是:“2006-05-30 00:00:00.0”

查询是将配置单元 table 中的数据读取到 Qlikview 中,因此理想情况下我不想事先定义变量,而更愿意动态地执行 select。如果我是 Hive 的新手,如果其中任何一个是愚蠢的,我深表歉意。

在子查询中计算 max_date 并与 table 交叉连接:

select * 
  from TABLE a
       cross join --cross join with single row
       (select max(TRANS_DATE) as max_trans_date from TABLE) b 
 where (a.TRANS_DATE > DATE_SUB(b.max_trans_date, 365)) 
   and (a.TRANS_DATE < b.max_trans_date);

具有解析功能:

select a.* from
(select a.*,
       max(TRANS_DATE) over() as max_trans_date 
  from TABLE a) a
 where (a.TRANS_DATE > DATE_SUB(a.max_trans_date, 365)) 
   and (a.TRANS_DATE < a.max_trans_date);