-----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.


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to