Re: aggregate function ? - Mailing list pgsql-novice

From Raimon Fernandez
Subject Re: aggregate function ?
Date
Msg-id 51ACF4CC-811F-4A05-8604-DD0B0CEC813B@montx.com
Whole thread Raw
In response to Re: aggregate function ?  (Richard Broersma Jr <rabroersma@yahoo.com>)
Responses Re: aggregate function ?  (Richard Broersma Jr <rabroersma@yahoo.com>)
List pgsql-novice
Hi,

I choose because it's an easy example, normally I would change for a
Date selection and another field.


The user selects a compte and a date interval, for example:

compte: 572 0000 01
date init: 15/01/2007
date end: 30/01/2007

The initial sum, would be the compte field plus a date init of the
year, in that case, 01/01/2007 to the date init, 15/01/2007. Here
we'll get the SUM of the two values (deure-haver), and this would be
the initial value of the sum_value to add, so the code would be:

SELECT SUM(deure)-SUM(haver) FROM assentaments WHERE
assentaments.compte='572000001' and assentaments.data >='2007-01-15'
and assentaments.data <='2007-01-30';

Regards,


rai




On 18/05/2007, at 06:49, Richard Broersma Jr wrote:

>
> --- Raimon Fernandez <coder@montx.com> wrote:
>> Is this the correct way to add a number to each sum_value ?
>
>>         (SELECT deure FROM assentaments WHERE oid=180108)+    sum
>                                                     ^^^^^^
> One question why did you choose oid=180108 to identify the row to
> use for adding to your sum.  Is
> there some sort of hidden relationship here that you can use craft
> a better select query?
> Basically, the question to ask is, what is the relationship between
> the rolling Sum and the
> initial "shifting" value.
>
> Regards,
> Richard Broersma Jr.
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>



pgsql-novice by date:

Previous
From: Richard Broersma Jr
Date:
Subject: Re: aggregate function ?
Next
From: Richard Broersma Jr
Date:
Subject: Re: aggregate function ?