Search Postgresql Archives

Re: complicated running aggregate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx   www.2ndQuadrant.us


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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux