Sim Zacks wrote:
> I am trying to build a query with a running total, but it is a bit
> complicated...Currently I'm generating this information using a plpsql loop, but I
> would like to change it to an SQL query, if possible.
>
It's hard to do a running total with the sort of requirements you have
using simple SQL. If you have PostgreSQL 8.4, it's much much easier to
do that using the SQL Window functions:
http://www.postgresql.org/docs/current/static/tutorial-window.html
If you're on an earlier version, using a loop in a function is not a bad
approach. Getting the query right without windowing is possible, but
painful enough that it may not be worth your trouble.
--
Greg Smith 2ndQuadrant US Baltimore, MD
PostgreSQL Training, Services and Support
greg@2ndQuadrant.com www.2ndQuadrant.us