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

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Window function SQL - can't quite figure it.
Дата
Msg-id CAKFQuwb1AE7fZbHzEDe1ePbbQY_Nck4umNVwOUT3fya-UFSMUw@mail.gmail.com
обсуждение исходный текст
Ответ на Window function SQL - can't quite figure it.  (Pál Teleki <ellenallhatatlan@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Pál Teleki
Дата:
Сообщение: Re: Window function - assistance appreicated. Can't figure it out.
Следующее
От: Pál Teleki
Дата:
Сообщение: Re: 2nd attempt: Window function SQL - can't quite figure it.