Re: Window function SQL - can't quite figure it.

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Pál Teleki <ellenallhatatlan(at)gmail(dot)com>
Cc: pgsql-novice novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Window function SQL - can't quite figure it.
Date: 2016-07-18 12:20:15
Message-ID: CAKFQuwb1AE7fZbHzEDe1ePbbQY_Nck4umNVwOUT3fya-UFSMUw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Sun, Jul 17, 2016 at 10:48 PM, Pál Teleki <ellenallhatatlan(at)gmail(dot)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.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Pál Teleki 2016-07-18 18:29:19 Re: 2nd attempt: Window function SQL - can't quite figure it.
Previous Message Pál Teleki 2016-07-18 03:18:58 Re: Window function - assistance appreicated. Can't figure it out.