我有一个包含hdfs的行的表。 我想计算表的每个id的日期平均差异。 这是我正在使用的查询,但它一直给我错误: -
select id, AVG(new_visit) over x+1 as avg_lag_btwn_visit
from (select id, date_visit, datediff(date_visit,LAG(date_visit)) over w > 1 as new_visit
from (select id, date_visit from table) a
window w as (partition by id order by date_visit)
) b
window x as (partition by id order by date_visit);
编辑: 样本输入: 12345,2018-01-01 12345,2018-01-12 23456,2018-02-01 12345,2018-01-20 23456,2018-02-20 34567,2018-03-01 样本输出: 12345,9.5 23456,19 34567,0
编译语句时出错:FAILED:SemanticException无法分解窗口调用到组中。至少有一个组必须仅依赖于输入列。还要检查循环依赖性。基础错误:无效函数datediff