Re: question about query
От | David Johnston |
---|---|
Тема | Re: question about query |
Дата | |
Msg-id | 010b01cc37f3$56952fa0$03bf8ee0$@yahoo.com обсуждение исходный текст |
Ответ на | Re: question about query (Linos <info@linos.es>) |
Список | pgsql-general |
-----Original Message----- i have created the union to get all the records (giving payments negative sign) but what i don't know how to do it is use a window function to create the column with the running total, any short example of syntax please? >>>>>>>>>> You'll need to check the documentation for the exact syntax but the following should work as desired. SELECT description, amount, transaction_date, SUM(amount) OVER (ORDER BY transaction_date, amount) FROM accountsreceivable You do NOT use a "GROUP BY" in this instance because the "OVER" clause following the SUM function turns it into a Window function which aggregates in the context of a virtual window. Using ORDER BY causes the SUM() function to behave like a Running Sum. You have not specified your version and Window functions are only available in newer releases (>=8.4 I believe). If you cannot use this then you will have to write a store procedure. David J.
В списке pgsql-general по дате отправления: