Re: Window function SQL - can't quite figure it. - Mailing list pgsql-novice

From David G. Johnston
Subject Re: Window function SQL - can't quite figure it.
Date
Msg-id CAKFQuwb1AE7fZbHzEDe1ePbbQY_Nck4umNVwOUT3fya-UFSMUw@mail.gmail.com
Whole thread Raw
In response to Window function SQL - can't quite figure it.  (Pál Teleki <ellenallhatatlan@gmail.com>)
List pgsql-novice
On Sun, Jul 17, 2016 at 10:48 PM, Pál Teleki <ellenallhatatlan@gmail.com> wrote:
Hi all,:


I'm struggling to get to grips with Window functions (DDL and DML at
end of post).

​You never asked a question...

I suppose your actual problem is that

group_key,
sum(amount) over (...)
GROUP BY​
 
​group_key

Is giving you an error.  This is expected.  You must write that fragment

group_key,
sum(sum(amount)) over (...)
GROUP BY group_key

The window sum is not an aggregate from the perspective of group by.  In the original you never aggregated "amount" nor was it part of the group by and thus an error.  turning "amount" into the aggregate "sum(amount)" is one valid solution.

David J.

pgsql-novice by date:

Previous
From: Pál Teleki
Date:
Subject: Re: Window function - assistance appreicated. Can't figure it out.
Next
From: Pál Teleki
Date:
Subject: Re: 2nd attempt: Window function SQL - can't quite figure it.