Partition by in Impala SQL throwing an error

北慕城南 提交于 2019-12-25 01:03:13

问题


I am trying to calculate the running total of loss by the months on Impala using TOAD

The following query is throwing the error -select list expression not produced by aggregation output (missing from group by clause )

select
segment,
year(open_dt) as open_year,
months,
sum(balance)
sum(loss) over (PARTITION by segment,year(open_dt) order by months) as NCL 
from

tableperf
where
year(open_dt) between 2015 and 2018

group by 1,2,3

回答1:


You are mixing aggregation and window functions. I think you might want:

select segment, year(open_dt) as open_year, months,
       sum(balance)
       sum(sum(loss)) over (PARTITION by segment, year(open_dt) order by months) as NCL 
from tableperf
where year(open_dt) between 2015 and 2018
group by 1, 2, 3;

This calculates the cumulative loss within each year. Note the use of sum(sum(loss)). The inner sum() is an aggregation function. The outer sum() is a window function.



来源:https://stackoverflow.com/questions/50201554/partition-by-in-impala-sql-throwing-an-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!