Re: (P)SQL for a sum with constraints - Mailing list pgsql-general

From hubert depesz lubaczewski
Subject Re: (P)SQL for a sum with constraints
Date
Msg-id 20090415104709.GA2704@depesz.com
Whole thread Raw
In response to (P)SQL for a sum with constraints  (Shug Boabby <shug.boabby@gmail.com>)
List pgsql-general
On Wed, Apr 15, 2009 at 11:09:49AM +0100, Shug Boabby wrote:
> Anyone have any ideas how to do this? I'm able to do it
> programmatically, but it's slow. Optimally I'd like to be able to do
> this in the DB. As you can see, it's a little trickier that the usual
> aggregate function with a GROUP BY and HAVING.

this is called cumulative sum, and can be done quite easily.

check this blogpost (but also its comments! - the c function is not
necessary!)
http://www.depesz.com/index.php/2007/08/17/rownum-anyone-cumulative-sum-in-one-query/

depesz

--
Linkedin: http://www.linkedin.com/in/depesz  /  blog: http://www.depesz.com/
jid/gtalk: depesz@depesz.com / aim:depeszhdl / skype:depesz_hdl / gg:6749007

pgsql-general by date:

Previous
From: Shug Boabby
Date:
Subject: (P)SQL for a sum with constraints
Next
From: Ow Mun Heng
Date:
Subject: pg_reorg -> Anyone has any experience with it?